NEST  2.6.0,not_revisioned_source_dir@0
aggregatedatum.h
Go to the documentation of this file.
1 /*
2  * aggregatedatum.h
3  *
4  * This file is part of NEST.
5  *
6  * Copyright (C) 2004 The NEST Initiative
7  *
8  * NEST is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * NEST is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with NEST. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #ifndef AGGREGATEDATUM_H
24 #define AGGREGATEDATUM_H
25 #include "datum.h"
26 #include "allocator.h"
27 #include "config.h"
28 
29 /*
30  Datum template for aggregate data types.
31 */
32 
33 /************************************************
34  The AggregateDatum template should be used for all
35  Datum objects which contain class objects (i.e. no
36  trivial types like int, long, char, etc.)
37 
38  AggregateDatum inherits some virtual functions from
39  its base class Datum which must be supplied.
40  Usually destruction should be trivial, though a
41  virtual destructor must be supplied.
42 
43  In order to avoid ambiguities with potential
44  base classes, no virtual operators should be used
45  in the Datum class, rather "unique" virtual
46  function names should be used.
47 
48  Particularly, the operator<< should not be defined
49  for base class Datum.
50 *************************************************/
51 
52 template <class C, SLIType *slt>
53 class AggregateDatum : public TypedDatum<slt>, public C
54 {
55  protected:
56  static sli::pool memory;
57  private:
58  virtual Datum * clone(void) const
59  {
60  return new AggregateDatum<C,slt>(*this);
61  }
62 
63 public:
66  AggregateDatum(const C& c): TypedDatum<slt>(),C(c) { }
67 
68  virtual ~AggregateDatum() {}
69 
70  bool equals(const Datum *dat) const
71  {
72  // The following construct works around the problem, that
73  // a direct dynamic_cast<const GenericDatum<D> * > does not seem
74  // to work.
75 
77  *ddc=dynamic_cast<AggregateDatum<C, slt> * >(const_cast< Datum *>(dat));
78 
79  if(ddc == NULL)
80  return false;
81 
82  return static_cast< C >(*ddc) == static_cast<C>(*this);
83 
84  }
85 
86  static void * operator new(size_t size)
87  {
88  if(size != memory.size_of())
89  return ::operator new(size);
90  return memory.alloc();
91  }
92 
93  static void operator delete(void *p, size_t size)
94  {
95  if(p == NULL)
96  return;
97  if(size != memory.size_of())
98  {
99  ::operator delete(p);
100  return;
101  }
102  memory.free(p);
103  }
104 
105  virtual void print(std::ostream &out) const;
106  virtual void pprint(std::ostream &out) const;
107  virtual void list(std::ostream &out, std::string prefix, int l) const;
108 
109  virtual void input_form(std::ostream &out) const
110  {
111  print(out);
112  }
113 
114  virtual void info(std::ostream &out) const
115  {
116  print(out);
117  }
118 
119 };
120 
121 template <class C, SLIType *slt>
122 void AggregateDatum<C,slt>::print(std::ostream &out) const
123 {
124  out << *dynamic_cast<C *>(const_cast<AggregateDatum<C,slt> *>(this));
125 }
126 
127 template <class C, SLIType *slt>
128 void AggregateDatum<C,slt>::pprint(std::ostream &out) const
129 {
130  print(out);
131 }
132 
133 template <class C, SLIType *slt>
134 void AggregateDatum<C,slt>::list(std::ostream &out, std::string prefix, int l) const
135 {
136  if(l==0)
137  prefix="-->"+prefix;
138  else
139  prefix=" "+prefix;
140 
141  out << prefix;
142  print(out);
143 }
144 
145 #endif
size_t size_of(void) const
Definition: allocator.h:128
AggregateDatum()
Definition: aggregatedatum.h:64
Definition: datum.h:166
virtual void print(std::ostream &out) const
Definition: nest_datums.cpp:34
const Name d("d")
Specific to Izhikevich 2003.
Definition: nest_names.h:83
void unset_executable()
Definition: datum.h:118
static sli::pool memory
Definition: aggregatedatum.h:56
virtual void list(std::ostream &out, std::string prefix, int l) const
Definition: aggregatedatum.h:134
virtual Datum * clone(void) const
Virtual copy constructor.
Definition: aggregatedatum.h:58
Definition: aggregatedatum.h:53
AggregateDatum(const C &c)
Definition: aggregatedatum.h:66
virtual void info(std::ostream &out) const
Definition: aggregatedatum.h:114
virtual void pprint(std::ostream &out) const
Definition: nest_datums.cpp:38
void * alloc(void)
allocate one element
Definition: allocator.h:137
void free(void *p)
put element back into the pool
Definition: allocator.h:155
pool is a specialized allocator class for many identical small objects.
Definition: allocator.h:50
Definition: datum.h:33
bool equals(const Datum *dat) const
Definition: aggregatedatum.h:70
virtual ~AggregateDatum()
Definition: aggregatedatum.h:68
AggregateDatum(const AggregateDatum< C, slt > &d)
Definition: aggregatedatum.h:65
const Name p("p")
current release probability (Tsodyks2_connection)
Definition: nest_names.h:218
const Name c("c")
Specific to Izhikevich 2003.
Definition: nest_names.h:62
sli::pool memory
Definition: arraydatum.h:47
virtual void input_form(std::ostream &out) const
Definition: aggregatedatum.h:109