realroot_doc 0.1.1
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.

:_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.

{*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.

{
  _index_of_var[s]=i+1;
  _var_of_index[i+1]=s;
  if(i+1>_nbvar) _nbvar=i+1;
  return  _var_of_index[i+1];
}
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.

{
  std::string  v;
  _nbvar=0;
  std::istringstream ins(s);
  while(ins.good())
    {
      ins >>v;
      this->let(_nbvar,v);
    }
  return *this;
}
std::string operator[] ( int  i)

Return the variable of index i.

Definition at line 11 of file variables.cpp.

References variables::_var_of_index.

{
  if(_var_of_index[i+1]!="")
    return _var_of_index[i+1];
  else
    {
      int sz=1,m=1;
      while(m<i) {m*=10; sz++;}
      char str[sz];
      sprintf(str,"%d",i);
      return std::string("x")+str;
    }
}
int operator[] ( const std::string &  s)

Return the index of the variable s.

Definition at line 61 of file variables.cpp.

{
  //  std::cout  <<">> "<<s<<" "<<_nbvar<<" ";
  if(s[0]=='x' && s.size()>1 )
    {
      const char* var=s.data()+1;
      //   _nbvar= std::max((int)_nbvar,atoi(var)+1);
      //   std::cout<<":"<<atoi(var)<<std::endl;
      return atoi(var);
    }
  else
    {
      if(_nbvar==0)
        {
          _nbvar++;
          _index_of_var[s]=_nbvar;
          _var_of_index[_nbvar]=s;
          return 0;
        }
      else 
        {
          int i=_index_of_var[s]-1;
          if(i<0)
            {
              while(_var_of_index[_nbvar]!="")
                {
                  _nbvar++;
                }
              i=_nbvar-1;
              //   std::cout<<"I  "<<i<<std::endl;
              _index_of_var[s]=_nbvar;
              _var_of_index[_nbvar]=s;
            }
          return i;
        }
    }
}
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.

{
  std::map<int,std::string>::const_iterator pt=_var_of_index.find(i+1);
  if(pt!= _var_of_index.end())
    return pt->second;
  else
    {
      int sz=1,m=1;
      while(m<i) {m*=10; sz++;}
      char str[sz];
      sprintf(str,"%d",i);
      return std::string("x")+str;
    }
}
int size ( void  ) const [inline]

Definition at line 87 of file variables.hpp.

References variables::_nbvar.

{return _nbvar;}

Member Data Documentation

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

Definition at line 68 of file variables.hpp.

int _nbvar

Definition at line 67 of file variables.hpp.

Referenced by variables::nbvar(), and variables::size().

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

Definition at line 69 of file variables.hpp.

Referenced by 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: