COPASI API  4.16.103
CKeyFactory.h
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2013 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 // Copyright (C) 2008 - 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 // Copyright (C) 2003 - 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 /**
16  * CKeyFactory class.
17  * This class is used to create a unique key whithin COPASI. It also allows
18  * retreival of the CCopasiObject the key is assigned to.
19  *
20  * Created for Copasi by Stefan Hoops 2003
21  * Copyright Stefan Hoops
22  */
23 
24 #ifndef COPASI_CKeyFactory
25 #define COPASI_CKeyFactory
26 
27 #include <string>
28 #include <map>
29 #include <stack>
30 
32 
33 class CCopasiObject;
34 
36 {
37 private:
38  class HashTable
39  {
40  private:
41  size_t mBeyond;
42  size_t mSize;
44  std::stack< size_t > mFree;
45 
46  public:
47  HashTable();
48  HashTable(const HashTable & src);
49  ~HashTable();
50  size_t add(CCopasiObject * pObject);
51  bool addFix(const size_t & index, CCopasiObject * pObject);
52  CCopasiObject * get(const size_t & index);
53  bool remove(const size_t & index);
54  };
55 
56  class CDecisionVector : private CVector< bool >
57  {
58  private:
60 
61  public:
62  CDecisionVector(const std::string & str);
63 
64  virtual ~CDecisionVector();
65 
66  const bool & operator()(const unsigned char & c) const;
67  };
68 
69  // Attributes
70 protected:
71  /**
72  * A map of hash tables for the prefixes.
73  */
74  std::map< std::string, HashTable > mKeyTable;
75 
76  /**
77  * Fast way to decide whether a character is a digit.
78  */
80 
81  /**
82  * Fast way to decide whether a character is a valid part of the prefix.
83  */
85 
86  // Operations
87 public:
88  /**
89  * check whether the key is valid
90  * @param const std::string & key
91  * @param const std::string & prefix (default: check for [_a-zA-Z]+_\d+)
92  * @return bool isValid
93  */
94  static bool isValidKey(const std::string & key,
95  const std::string & prefix = "");
96 
97  /**
98  * Default constructor
99  */
100  CKeyFactory();
101 
102  /**
103  * Destructor
104  */
105  ~CKeyFactory();
106 
107  /**
108  * Add an object with a key generated from the given prefix to the key map.
109  * The return value is the actually generated key.
110  * @param const std::string & prefix
111  * @param CCopasiObject * pObject
112  * @return std::string key
113  */
114  std::string add(const std::string & prefix, CCopasiObject * pObject);
115 
116  /**
117  * Add an object with a fix given key.
118  * The return value indicate whether the key was actually inserted.
119  * @param const std::string & key
120  * @param CCopasiObject * pObject
121  * @return bool success
122  */
123  bool addFix(const std::string & key, CCopasiObject * pObject);
124 
125  /**
126  * Remove the key and the related object from the key map.
127  * @param const std::string & key
128  * @return bool success
129  */
130  bool remove(const std::string & key);
131 
132  /**
133  * Retrieve the object referred by key from the key map.
134  * @param const std::string & key
135  * @return CCopasiObject * pObject
136  */
137  CCopasiObject * get(const std::string & key);
138 };
139 
140 #endif // COPASI_CKeyFactory
CVector< CCopasiObject * > mTable
Definition: CKeyFactory.h:43
std::map< std::string, HashTable > mKeyTable
Definition: CKeyFactory.h:74
static CDecisionVector isDigit
Definition: CKeyFactory.h:79
static CDecisionVector isPrefix
Definition: CKeyFactory.h:84
static bool isValidKey(const std::string &key, const std::string &prefix="")
Definition: CKeyFactory.cpp:30
std::stack< size_t > mFree
Definition: CKeyFactory.h:44
bool addFix(const std::string &key, CCopasiObject *pObject)
std::string add(const std::string &prefix, CCopasiObject *pObject)
size_t add(CCopasiObject *pObject)
Definition: CKeyFactory.cpp:91
bool addFix(const size_t &index, CCopasiObject *pObject)
const bool & operator()(const unsigned char &c) const
Definition: CKeyFactory.cpp:72