API  Version 2.0.1
Low-Latency HFT API
 All Classes Functions Variables
api2UserCommands.h
1 #ifndef api2_UserParams_h
2 #define api2_UserParams_h
3 #include <baseCommands.h>
4 #include <sgDebugLog.h>
5 namespace API2 {
6 
10 enum UserParamsError
11 {
12  UserParamsError_OK,
13  UserParamsError_KeyNotFound,
14  UserParamsError_DataTypeMismatch
15 };
16 
21 {
25  std::map<std::string,BaseType *> _userParams;
26 
30  CREATE_FIELD_DERIVED( int, ApiIndex);
31 public:
32 
39  UserParams(const std::string &frontendDesign,const char *buf = NULL);
40 
47  int serialize(char *buf,int apiIndex);
48 
49 
56  template<class T>
57  UserParamsError setValue(const std::string &key,const T &val)
58  {
59  std::map<std::string,BaseType *>::iterator it = _userParams.find(key);
60  if(it == _userParams.end())
61  {
62  std::cout<<"Key not found : "<<key;
63 
64  return UserParamsError_KeyNotFound;
65  }
66  else
67  {
68  DerivedType<T> *value = dynamic_cast<DerivedType<T> *>(it->second);
69  if(value == NULL)
70  {
71  std::cout<<"Data Type Mismatch for "
72  <<key<<" "
73  << typeid(val).name()
74  <<std::endl;
75  //it->second->printType();
76  return UserParamsError_DataTypeMismatch;
77  }
78  else
79  {
80  value->setValue(val);
81  return UserParamsError_OK;
82  }
83  }
84  }
85 
86 
93  template<class T>
94  UserParamsError getValue(const std::string &key,T &val)
95  {
96  std::map<std::string,BaseType *>::iterator it = _userParams.find(key);
97  if(it == _userParams.end())
98  {
99  return UserParamsError_KeyNotFound;
100  }
101  else
102  {
103  DerivedType<T> *value = dynamic_cast<DerivedType<T> *>(it->second);
104  if(value == NULL)
105  {
106  std::cout<<"Data Type Mismatch for "<<key<<std::endl;
107  return UserParamsError_DataTypeMismatch;
108  }
109  else
110  {
111  val = value->getValue();
112  return UserParamsError_OK;
113  }
114  }
115  }
116  ~UserParams();
117 };
118 }
119 #endif
int serialize(char *buf, int apiIndex)
serialize
The API2_UserParams class.
Definition: api2UserCommands.h:20
UserParamsError setValue(const std::string &key, const T &val)
setValue
Definition: api2UserCommands.h:57
UserParamsError getValue(const std::string &key, T &val)
getValue
Definition: api2UserCommands.h:94
The AbstractUserParams class.
Definition: baseCommands.h:278
UserParams(const std::string &frontendDesign, const char *buf=NULL)
API2_UserParams.
The DerivedType class.
Definition: baseCommands.h:79