user_info.cc

Go to the documentation of this file.
00001 #ifndef USER_INFO_CC
00002 #define USER_INFO_CC
00003 
00004 #include "user_info.hh"
00005 
00006 user_info::user_info(const user_info &original) :
00007   data_base(original),
00008   _d_map(original._d_map),
00009   _i_map(original._i_map),
00010   _s_map(original._s_map),
00011   _b_map(original._b_map),
00012   _darray_map(original._darray_map),
00013   _iarray_map(original._iarray_map),
00014   _sarray_map(original._sarray_map),
00015   _barray_map(original._barray_map)
00016 {};
00017 
00018 void user_info::clear_data(){
00019   _d_map.clear();
00020   _i_map.clear();
00021   _s_map.clear();
00022   _b_map.clear();
00023   _darray_map.clear();
00024   _iarray_map.clear();
00025   _sarray_map.clear();
00026   _barray_map.clear();
00027 }
00028 
00029 void user_info::dump_contents(){
00030 
00031   Message::send(MSG::NORMAL,__FUNCTION__," Start contents dump...");
00032   std::string msg("");
00033 
00034   if(_d_map.size()){
00035     msg ="Contents of double variables shown below.\n";
00036     msg+=Form("  %-20s ... Value\n","Key");
00037     for(std::map<std::string,double>::const_iterator iter(_d_map.begin());
00038     iter!=_d_map.end();
00039     ++iter)
00040       msg+=Form("  %-20s ... %g\n",(*iter).first.c_str(), (*iter).second);
00041     Message::send(MSG::NORMAL,__FUNCTION__,msg.c_str());
00042   }
00043 
00044   if(_i_map.size()){
00045     msg ="Contents of int variables shown below.\n";
00046     msg+=Form("  %-20s ... Value\n","Key");
00047     for(std::map<std::string,int>::const_iterator iter(_i_map.begin());
00048     iter!=_i_map.end();
00049     ++iter)
00050       msg+=Form("  %-20s ... %d\n",(*iter).first.c_str(), (*iter).second);
00051     Message::send(MSG::NORMAL,__FUNCTION__,msg.c_str());
00052   }
00053 
00054   if(_s_map.size()){
00055     msg ="Contents of std::string variables shown below.\n";
00056     msg+=Form("  %-20s ... Value\n","Key");
00057     for(std::map<std::string,std::string>::const_iterator iter(_s_map.begin());
00058     iter!=_s_map.end();
00059     ++iter)
00060       msg+=Form("  %-20s ... %s\n",(*iter).first.c_str(), (*iter).second.c_str());
00061     Message::send(MSG::NORMAL,__FUNCTION__,msg.c_str());
00062   }
00063 
00064   if(_b_map.size()){
00065     msg ="Contents of bool variables shown below.\n";
00066     msg+=Form("  %-20s ... Value\n","Key");
00067     for(std::map<std::string,bool>::const_iterator iter(_b_map.begin());
00068     iter!=_b_map.end();
00069     ++iter)
00070       msg+=Form("  %-20s ... %d\n",(*iter).first.c_str(), (int)((*iter).second));
00071     Message::send(MSG::NORMAL,__FUNCTION__,msg.c_str());
00072   }
00073   
00074   if(_darray_map.size()){
00075     msg ="Contents of double array shown below.\n";
00076     for(std::map<std::string,std::vector<double> >::const_iterator iter(_darray_map.begin());
00077     iter!=_darray_map.end();
00078     ++iter){
00079       msg+=Form("  Key=%-20s\n    ",(*iter).first.c_str());
00080       int ctr=1;
00081       for(std::vector<double>::const_iterator cont_iter((*iter).second.begin());
00082       cont_iter!=(*iter).second.end();
00083       ++cont_iter){
00084     msg+=Form("%g ",(*cont_iter));
00085     ctr++;
00086     if(ctr%8==0)
00087       msg+="\n    ";
00088       }
00089     }
00090     Message::send(MSG::NORMAL,__FUNCTION__,msg.c_str());
00091   }
00092 
00093   if(_iarray_map.size()){
00094     msg ="Contents of int array shown below.\n";
00095     for(std::map<std::string,std::vector<int> >::const_iterator iter(_iarray_map.begin());
00096     iter!=_iarray_map.end();
00097     ++iter){
00098       msg+=Form("  Key=%-20s\n    ",(*iter).first.c_str());
00099       int ctr=1;
00100       for(std::vector<int>::const_iterator cont_iter((*iter).second.begin());
00101       cont_iter!=(*iter).second.end();
00102       ++cont_iter){
00103     msg+=Form("%d ",(*cont_iter));
00104     ctr++;
00105     if(ctr%8==0)
00106       msg+="\n    ";
00107       }
00108     }
00109     Message::send(MSG::NORMAL,__FUNCTION__,msg.c_str());
00110   }
00111 
00112   if(_sarray_map.size()){
00113     msg ="Contents of std::string array shown below.\n";
00114     for(std::map<std::string,std::vector<std::string> >::const_iterator iter(_sarray_map.begin());
00115     iter!=_sarray_map.end();
00116     ++iter){
00117       msg+=Form("  Key=%-20s\n    ",(*iter).first.c_str());
00118       int ctr=1;
00119       for(std::vector<std::string>::const_iterator cont_iter((*iter).second.begin());
00120       cont_iter!=(*iter).second.end();
00121       ++cont_iter){
00122     msg+=Form("%s ",(*cont_iter).c_str());
00123     ctr++;
00124     if(ctr%8==0)
00125       msg+="\n    ";
00126       }
00127     }
00128     Message::send(MSG::NORMAL,__FUNCTION__,msg.c_str());
00129   }
00130 
00131   if(_barray_map.size()){
00132     msg ="Contents of bool array shown below.\n";
00133     for(std::map<std::string,std::vector<bool> >::const_iterator iter(_barray_map.begin());
00134     iter!=_barray_map.end();
00135     ++iter){
00136       msg+=Form("  Key=%-20s\n    ",(*iter).first.c_str());
00137       int ctr=1;
00138       for(std::vector<bool>::const_iterator cont_iter((*iter).second.begin());
00139       cont_iter!=(*iter).second.end();
00140       ++cont_iter){
00141     msg+=Form("%d ",(int)(*cont_iter));
00142     ctr++;
00143     if(ctr%8==0)
00144       msg+="\n    ";
00145       }
00146     }
00147     Message::send(MSG::NORMAL,__FUNCTION__,msg.c_str());
00148   }
00149   Message::send(MSG::NORMAL,__FUNCTION__," End of dump...");
00150 }
00151 
00152 void user_info::append(std::string key, double value){
00153   if(_darray_map.find(key)==_darray_map.end()) 
00154     _darray_map[key]=std::vector<double>();
00155   _darray_map[key].push_back(value);
00156 }
00157 
00158 void user_info::append(std::string key, int value){
00159   if(_iarray_map.find(key)==_iarray_map.end())
00160     _iarray_map[key]=std::vector<int>();
00161   _iarray_map[key].push_back(value);
00162 }
00163 
00164 void user_info::append(std::string key, std::string value){
00165   if(_sarray_map.find(key)==_sarray_map.end())
00166     _sarray_map[key]=std::vector<std::string>();
00167   _sarray_map[key].push_back(value);
00168 }
00169 
00170 void user_info::append(std::string key, bool value){
00171   if(_barray_map.find(key)==_barray_map.end())
00172     _barray_map[key]=std::vector<bool>();
00173   _barray_map[key].push_back(value);
00174 }
00175 
00176 double user_info::get_double(std::string key) const {  
00177   std::map<std::string,double>::const_iterator item(_d_map.find(key));
00178   if(item==_d_map.end()){
00179     Message::send(MSG::ERROR,__FUNCTION__,Form("Key \"%s\" does not exist!", key.c_str()));
00180     return 0;
00181   }
00182   return (*item).second;
00183 }
00184 
00185 int user_info::get_int(std::string key) const {
00186   std::map<std::string,int>::const_iterator item(_i_map.find(key));
00187   if(item==_i_map.end()){
00188     Message::send(MSG::ERROR,__FUNCTION__,Form("Key \"%s\" does not exist!", key.c_str()));
00189     return 0;
00190   }
00191   return (*item).second;
00192 }
00193 
00194 std::string user_info::get_string(std::string key) const {
00195   std::map<std::string,std::string>::const_iterator item(_s_map.find(key));
00196   if(item==_s_map.end()){
00197     Message::send(MSG::ERROR,__FUNCTION__,Form("Key \"%s\" does not exist!", key.c_str()));
00198     return 0;
00199   }
00200   return (*item).second;
00201 }
00202 
00203 
00204 bool user_info::get_bool(std::string key) const {
00205   std::map<std::string,bool>::const_iterator item(_b_map.find(key));
00206   if(item==_b_map.end()){
00207     Message::send(MSG::ERROR,__FUNCTION__,Form("Key \"%s\" does not exist!", key.c_str()));
00208     return 0;
00209   }
00210   return (*item).second;
00211 }
00212 
00213 std::vector<double>* user_info::get_darray(std::string key)  {
00214   std::map<std::string,std::vector<double> >::iterator item(_darray_map.find(key));
00215   if(item==_darray_map.end()){
00216     Message::send(MSG::ERROR,__FUNCTION__,Form("Key \"%s\" does not exist!", key.c_str()));
00217     return 0;
00218   }
00219   return &((*item).second);
00220 }
00221 
00222 std::vector<int>* user_info::get_iarray(std::string key)  {
00223   std::map<std::string,std::vector<int> >::iterator item(_iarray_map.find(key));
00224   if(item==_iarray_map.end()){
00225     Message::send(MSG::ERROR,__FUNCTION__,Form("Key \"%s\" does not exist!", key.c_str()));
00226     return 0;
00227   }
00228   return &((*item).second);
00229 }
00230 
00231 std::vector<std::string>* user_info::get_sarray(std::string key)  {
00232   std::map<std::string,std::vector<std::string> >::iterator item(_sarray_map.find(key));
00233   if(item==_sarray_map.end()){
00234     Message::send(MSG::ERROR,__FUNCTION__,Form("Key \"%s\" does not exist!", key.c_str()));
00235     return 0;
00236   }
00237   return &((*item).second);
00238 }
00239 
00240 std::vector<bool>* user_info::get_barray(std::string key)  {
00241   std::map<std::string,std::vector<bool> >::iterator item(_barray_map.find(key));
00242   if(item==_barray_map.end()){
00243     Message::send(MSG::ERROR,__FUNCTION__,Form("Key \"%s\" does not exist!", key.c_str()));
00244     return 0;
00245   }
00246   return &((*item).second);
00247 }
00248 
00249 
00250 #endif

Generated on Mon Apr 7 15:35:12 2014 for MyProject by  doxygen 1.4.7