Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Roccom_map< Object > Class Template Reference

Supports mapping from names to handles and vice-versa for a module, window, function, or attribute. More...

#include <maps.h>

Inheritance diagram for Roccom_map< Object >:
Collaboration diagram for Roccom_map< Object >:

Public Types

typedef Object value_type
 

Public Member Functions

 Roccom_map ()
 
 ~Roccom_map ()
 
int add_object (std::string name, Object t, bool is_const=false) throw (COM_exception)
 Insert an object into the table. More...
 
void remove_object (std::string name, bool is_const=false) throw (COM_exception)
 Remove an object from the table. More...
 
bool is_immutable (int i) const
 whether the object mutable More...
 
const Object & operator[] (int i) const throw (COM_exception)
 Access an object using its handle. More...
 
Object & operator[] (int i) throw (COM_exception)
 
const std::string & name (int i) const
 Name of the object. More...
 
int size () const
 
std::pair< int, Object * > find (const std::string &name, bool is_const=false)
 
std::vector< std::string > get_names ()
 

Protected Attributes

I2O i2o
 Mapping from index to objects. More...
 
N2I n2i
 Mapping from names to indices. More...
 
std::list< int > salvaged
 List of salvaged indices. More...
 
std::vector< std::string > names
 Name of the objects. More...
 

Private Types

typedef std::vector< Object > I2O
 Mapping from indices to objects. More...
 
typedef std::map< std::string,
int > 
N2I
 Mapping from names to indices. More...
 

Detailed Description

template<class Object>
class Roccom_map< Object >

Supports mapping from names to handles and vice-versa for a module, window, function, or attribute.

Definition at line 43 of file maps.h.

Member Typedef Documentation

typedef std::vector<Object> I2O
private

Mapping from indices to objects.

Definition at line 44 of file maps.h.

typedef std::map<std::string, int> N2I
private

Mapping from names to indices.

Definition at line 45 of file maps.h.

typedef Object value_type

Definition at line 47 of file maps.h.

Constructor & Destructor Documentation

Roccom_map ( )
inline

Definition at line 49 of file maps.h.

49 {}
~Roccom_map ( )
inline

Definition at line 50 of file maps.h.

50 {}

Member Function Documentation

int add_object ( std::string  name,
Object  t,
bool  is_const = false 
)
throw (COM_exception
)

Insert an object into the table.

Definition at line 97 of file maps.h.

References i, and if().

Referenced by Function_map::add_object().

99 {
100  if (is_const) name.append( " (const)");
101 
102  N2I::iterator it = n2i.find(name);
103  int i = ( it == n2i.end()) ? -1 : it->second;
104 
105  if ( i>0)
106  { i2o[i] = t; }
107  else if ( salvaged.empty()) {
108  i=i2o.size(); n2i[name] = i;
109  i2o.push_back( t); names.push_back( name);
110  }
111  else {
112  i=salvaged.front(); salvaged.pop_front();
113  n2i[name] = i; i2o[i] = t; names[i] = name;
114  }
115  return i;
116 }
if(dy > dx)
N2I n2i
Mapping from names to indices.
Definition: maps.h:91
const std::string & name(int i) const
Name of the object.
Definition: maps.h:76
I2O i2o
Mapping from index to objects.
Definition: maps.h:90
std::vector< std::string > names
Name of the objects.
Definition: maps.h:93
blockLoc i
Definition: read.cpp:79
std::list< int > salvaged
List of salvaged indices.
Definition: maps.h:92

Here is the call graph for this function:

Here is the caller graph for this function:

std::pair<int,Object *> find ( const std::string &  name,
bool  is_const = false 
)
inline

Definition at line 80 of file maps.h.

80  {
81  N2I::iterator it=n2i.find( is_const?name+"(const)":name);
82  if ( it == n2i.end())
83  return std::pair<int,Object *>(-1,NULL);
84  else
85  return std::pair<int,Object *>(it->second, &i2o[ it->second]);
86  }
N2I n2i
Mapping from names to indices.
Definition: maps.h:91
const std::string & name(int i) const
Name of the object.
Definition: maps.h:76
I2O i2o
Mapping from index to objects.
Definition: maps.h:90
std::vector<std::string> get_names ( )
inline

Definition at line 88 of file maps.h.

88 { return names; }
std::vector< std::string > names
Name of the objects.
Definition: maps.h:93
bool is_immutable ( int  i) const
inline

whether the object mutable

Definition at line 61 of file maps.h.

62  { return names[i].find(" (const)")!=std::string::npos; }
std::vector< std::string > names
Name of the objects.
Definition: maps.h:93
blockLoc i
Definition: read.cpp:79
const std::string& name ( int  i) const
inline

Name of the object.

Definition at line 76 of file maps.h.

Referenced by Roccom_base::print_profile(), and Roccom_base::set_profiling_barrier().

76 { return names[i]; }
std::vector< std::string > names
Name of the objects.
Definition: maps.h:93
blockLoc i
Definition: read.cpp:79

Here is the caller graph for this function:

const Object& operator[] ( int  i) const
throw (COM_exception
)
inline

Access an object using its handle.

Definition at line 65 of file maps.h.

65  {
66  if ( i>=(int)i2o.size()) throw COM_exception( COM_UNKNOWN_ERROR);
67  return i2o[i];
68  }
Encapsulates the states of an exception.
I2O i2o
Mapping from index to objects.
Definition: maps.h:90
blockLoc i
Definition: read.cpp:79
Object& operator[] ( int  i)
throw (COM_exception
)
inline

Definition at line 70 of file maps.h.

70  {
71  if ( i>=(int)i2o.size()) throw COM_exception( COM_UNKNOWN_ERROR);
72  return i2o[i];
73  }
Encapsulates the states of an exception.
I2O i2o
Mapping from index to objects.
Definition: maps.h:90
blockLoc i
Definition: read.cpp:79
void remove_object ( std::string  name,
bool  is_const = false 
)
throw (COM_exception
)

Remove an object from the table.

Definition at line 119 of file maps.h.

References COM_UNKNOWN_ERROR.

120  {
121  if (is_const) name.append( " (const)");
122 
123  N2I::iterator it = n2i.find(name);
124  if ( it == n2i.end()) throw COM_exception( COM_UNKNOWN_ERROR);
125  salvaged.push_back( it->second);
126  n2i.erase(it);
127 }
N2I n2i
Mapping from names to indices.
Definition: maps.h:91
const std::string & name(int i) const
Name of the object.
Definition: maps.h:76
Encapsulates the states of an exception.
std::list< int > salvaged
List of salvaged indices.
Definition: maps.h:92
int size ( ) const
inline

Definition at line 78 of file maps.h.

Referenced by Roccom_base::set_profiling_barrier().

78 { return names.size(); }
std::vector< std::string > names
Name of the objects.
Definition: maps.h:93

Here is the caller graph for this function:

Member Data Documentation

N2I n2i
protected

Mapping from names to indices.

Definition at line 91 of file maps.h.

Referenced by Roccom_map< std::pair< void *, std::set< std::string > > >::find().

std::list<int> salvaged
protected

List of salvaged indices.

Definition at line 92 of file maps.h.


The documentation for this class was generated from the following file: