variables Struct Reference

#include <variables.hpp>

List of all members.

Public Member Functions

Public Attributes

Static Public Attributes


Detailed Description

Definition at line 65 of file variables.hpp.


Constructor & Destructor Documentation

variables (  )  [inline]

Definition at line 71 of file variables.hpp.

00071 :_nbvar(0) {}

variables ( const char *  s  )  [inline]

Construction the list of variables from a string of the form "a b c ...".

Definition at line 74 of file variables.hpp.

00074 {*this=s;}


Member Function Documentation

std::string & let ( int  i,
const std::string &  s 
)

Assign the variable of index i to be s.

Definition at line 40 of file variables.cpp.

References variables::_index_of_var, variables::_nbvar, and variables::_var_of_index.

Referenced by variables::operator=().

00041 {
00042   _index_of_var[s]=i+1;
00043   _var_of_index[i+1]=s;
00044   if(i+1>_nbvar) _nbvar=i+1;
00045   return  _var_of_index[i+1];
00046 }

int nbvar (  )  const [inline]
variables & operator= ( const char *  s  ) 

Assign a set of variables from a string of the form "a b c ...".

Definition at line 48 of file variables.cpp.

References variables::_nbvar, and variables::let().

00049 {
00050   std::string  v;
00051   _nbvar=0;
00052   std::istringstream ins(s);
00053   while(ins.good())
00054     {
00055       ins >>v;
00056       this->let(_nbvar,v);
00057     }
00058   return *this;
00059 }

int operator[] ( const std::string &  s  ) 

Return the index of the variable s.

Definition at line 61 of file variables.cpp.

References variables::_index_of_var, variables::_nbvar, and variables::_var_of_index.

00062 {
00063   //  std::cout  <<">> "<<s<<" "<<_nbvar<<" ";
00064   if(s[0]=='x' && s.size()>1 )
00065     {
00066       const char* var=s.data()+1;
00067       //   _nbvar= std::max((int)_nbvar,atoi(var)+1);
00068       //   std::cout<<":"<<atoi(var)<<std::endl;
00069       return atoi(var);
00070     }
00071   else
00072     {
00073       if(_nbvar==0)
00074         {
00075           _nbvar++;
00076           _index_of_var[s]=_nbvar;
00077           _var_of_index[_nbvar]=s;
00078           return 0;
00079         }
00080       else 
00081         {
00082           int i=_index_of_var[s]-1;
00083           if(i<0)
00084             {
00085               while(_var_of_index[_nbvar]!="")
00086                 {
00087                   _nbvar++;
00088                 }
00089               i=_nbvar-1;
00090               //   std::cout<<"I  "<<i<<std::endl;
00091               _index_of_var[s]=_nbvar;
00092               _var_of_index[_nbvar]=s;
00093             }
00094           return i;
00095         }
00096     }
00097 }

std::string operator[] ( int  i  )  const

Return the variable of index i.

Definition at line 25 of file variables.cpp.

References variables::_var_of_index.

00026 {
00027   std::map<int,std::string>::const_iterator pt=_var_of_index.find(i+1);
00028   if(pt!= _var_of_index.end())
00029     return pt->second;
00030   else
00031     {
00032       int sz=1,m=1;
00033       while(m<i) {m*=10; sz++;}
00034       char str[sz];
00035       sprintf(str,"%d",i);
00036       return std::string("x")+str;
00037     }
00038 }

std::string operator[] ( int  i  ) 

Return the variable of index i.

Definition at line 11 of file variables.cpp.

References variables::_var_of_index.

00012 {
00013   if(_var_of_index[i+1]!="")
00014     return _var_of_index[i+1];
00015   else
00016     {
00017       int sz=1,m=1;
00018       while(m<i) {m*=10; sz++;}
00019       char str[sz];
00020       sprintf(str,"%d",i);
00021       return std::string("x")+str;
00022     }
00023 }

int size ( void   )  const [inline]

Definition at line 87 of file variables.hpp.

References variables::_nbvar.

00087 {return _nbvar;}


Member Data Documentation

std::map<std::string,int> _index_of_var

Definition at line 68 of file variables.hpp.

Referenced by variables::let(), and variables::operator[]().

int _nbvar
std::map<int,std::string> _var_of_index

Definition at line 69 of file variables.hpp.

Referenced by variables::let(), and variables::operator[]().

variables default_ [static]

Definition at line 89 of file variables.hpp.

Referenced by mmx::sparse::print().


The documentation for this struct was generated from the following files:

Generated on 6 Dec 2012 for realroot by  doxygen 1.6.1