aboutsummaryrefslogtreecommitdiff
path: root/PDContainer/include/ContainerBase.h
blob: 7cc54b90d861a8158945045ad695bc83d4080986 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// *********************(c)*2004*********************>
// -holzilib--holzilib--holzilib--holzilib--holzilib->
// ++++PD-External++by+Georg+Holzmann++grh@gmx.at++++>
//
// PDContainer: 
// this is a port of the containers from the C++ STL
// (Standard Template Library)
// for usage see the documentation and PD help files
// for license see readme.txt
//
// ContainerBase.h 


#ifndef _container_base_h___
#define _container_base_h___


#include "include/GlobalStuff.h"
#include <map>

using std::map;


//---------------------------------------------------
/* this is the base class of all the containers
 */
template <class ContainerType, class ContTypeIterator>
class ContainerBase
{
 protected:

  /* this is the static container with all the datas
   * the string is the namespace of the Container
   */
  static map<string,ContainerType> data_;

  /* holds the number of the current namespace
   * (the string of the namespace is stored in the map above)
   */
  string h_namespace_;

  /* this string is the name of the datatype
   * (e.g. h_set, h_map, ...)
   */
  string dataname_;

 private:

  /* Copy Construction is not allowed
   */
  ContainerBase(const ContainerBase<ContainerType,ContTypeIterator> &src)
    { }

  /* assignement operator is not allowed
   */
  const ContainerBase<ContainerType,ContTypeIterator>& operator = 
    (const ContainerBase<ContainerType,ContTypeIterator>&)
    { }

 public:

  /* Standard Constructor
   * no namespace
   */
  ContainerBase()
    { }

  /* Destructor
   */
  virtual ~ContainerBase() 
    { } 

  /* sets the namespace variable
   */
  void setNamespace(string h_namespace) 
    {   
      h_namespace_ = h_namespace;
      //ContainerType container;
      //data_.insert(std::pair<string,ContainerType>(h_namespace_,container));
    }

  /* get the namespace string
   */ 
  string getNamespace() const
    {   return h_namespace_;   }

  /* prints out the help text
   */
  virtual void help();

  /* clears all the data of the current namespaces
   * in all objects from the same container
   */
  virtual void clearNamespace()
    { data_.erase(h_namespace_); }

  /* returns a reference to the whole Container
  * of the current namespace
   */
  virtual ContainerType &getAll()
  { return data_[h_namespace_]; }
  
  /* clears all the data of the current container
   * ( in all namespaces !!!!! )
   * so be carefull !!!
   */
  virtual void clearAll()
    { data_.clear(); }

  /* get the size of the container
   */
  virtual int getSize() const
    {  return data_[h_namespace_].size();  }
};


//---------------------------------------------------
/* defines the static members
 */
template<class ContainerType, class ContTypeIterator>
map<string,ContainerType> ContainerBase<ContainerType,ContTypeIterator>::data_;

//---------------------------------------------------
/* prints out the help text
 */
template<class ContainerType, class ContTypeIterator>
void ContainerBase<ContainerType,ContTypeIterator>::help()
{
  post("\nPD-Container, Version: "PDC_VERSION"");
  post("object: %s",dataname_.c_str());
  post("------------------------------------------");
  post("this is an implementation of the container");
  post("objects from the Standard Template");
  post("Library (STL) of C++");
  post("for documentation see the help patches");
  post("(by Georg Holzmann <grh@mur.at>, 2004-2005)");
  post("------------------------------------------\n");
}



#endif //_container_base_h___