NEST  2.6.0,not_revisioned_source_dir@0
datum.h
Go to the documentation of this file.
1 /*
2  * datum.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 DATUM_H
24 #define DATUM_H
25 
26 #include "slitype.h"
27 
28 /***********************************************************/
29 /* Datum */
30 /* ----- */
31 /* base class for all Data Objects */
32 /***********************************************************/
33 class Datum
34 {
35 
36  friend class Token;
37 
42  virtual Datum * clone(void) const = 0;
43 
44 
52  virtual Datum * get_ptr()
53  {
54  return clone();
55  }
56 
57  protected:
58  // Putting the following variables here, avoids a number of virtual
59  // functions.
60 
61  const SLIType *type;
63  mutable
64  unsigned int reference_count_;
66 
67 
68  Datum() :
69  type(NULL),
70  action(NULL),
72  executable_(true)
73  {}
74 
75 
76  Datum(const SLIType *t) :
77  type(t),
78  action(t->getaction()),
80  executable_(true)
81  { }
82 
84 
85 
86  public:
87 
88  virtual ~Datum() {};
89 
90 
91  void addReference() const
92  {
94  }
95 
97  {
99  if(reference_count_==0)
100  delete this;
101  }
102 
103  size_t numReferences() const
104  {
105  return reference_count_;
106  }
107 
108  bool is_executable() const
109  {
110  return executable_;
111  }
112 
114  {
115  executable_=true;
116  }
117 
119  {
120  executable_=false;
121  }
122 
123  virtual void print(std::ostream & ) const =0;
124  virtual void pprint(std::ostream &) const =0;
125 
126  virtual void list(std::ostream &o, std::string prefix, int l) const
127  {
128  if(l==0)
129  prefix="-->"+prefix;
130  else
131  prefix=" "+prefix;
132  o << prefix;
133  print(o);
134  }
135 
136  virtual void input_form(std::ostream &o) const
137  {
138  pprint(o);
139  }
140 
141  virtual bool equals(const Datum *d) const
142  {
143  return this == d;
144  }
145 
146  virtual void info(std::ostream &) const;
147 
148  const Name & gettypename(void) const
149  {
150  return type->gettypename();
151  }
152 
153  bool isoftype(SLIType const &t) const
154  {
155  return (type==&t); // or: *type==t, there is only one t with same contents !
156  }
157 
159  {
160  action->execute(i);
161  }
162 
163 };
164 
165 template<SLIType * slt >
166 class TypedDatum: public Datum
167 {
168  public:
170  :Datum(slt)
171  { }
172 
173 // This is here solely for default assignment operators in
174 // derived classes synthesized by the compiler. It does nothing but return itself.
175  protected:
178 
179 };
180 
181 template<SLIType * slt >
182 inline
184 {
185  // assert( type == d.type );
186  return *this;
187 }
188 
189 
190 
191 #endif
192 
void set_executable()
Definition: datum.h:113
virtual ~Datum()
Definition: datum.h:88
size_t numReferences() const
Definition: datum.h:103
Definition: datum.h:166
Datum()
Definition: datum.h:68
const Name d("d")
Specific to Izhikevich 2003.
Definition: nest_names.h:83
void unset_executable()
Definition: datum.h:118
virtual void pprint(std::ostream &) const =0
Definition: slifunction.h:35
virtual Datum * get_ptr()
Returns a reference counted pointer to the datum, or a new pointer, if the type does not support refe...
Definition: datum.h:52
Represent strings by ints to facilitate fast comparison.
Definition: name.h:53
const TypedDatum< slt > & operator=(const TypedDatum< slt > &)
Definition: datum.h:183
void execute(SLIInterpreter *i)
Definition: datum.h:158
virtual bool equals(const Datum *d) const
Definition: datum.h:141
void addReference() const
Definition: datum.h:91
virtual void list(std::ostream &o, std::string prefix, int l) const
Definition: datum.h:126
void removeReference()
Definition: datum.h:96
virtual void input_form(std::ostream &o) const
Definition: datum.h:136
bool isoftype(SLIType const &t) const
Definition: datum.h:153
bool executable_
Definition: datum.h:65
Definition: interpret.h:69
Datum(const SLIType *t)
Definition: datum.h:76
Definition: slitype.h:49
const Name & gettypename(void) const
Definition: datum.h:148
virtual void info(std::ostream &) const
Definition: datum.cc:34
const SLIType * type
Pointer to type object.
Definition: datum.h:61
const Name & gettypename(void) const
Definition: slitype.h:66
virtual void print(std::ostream &) const =0
virtual Datum * clone(void) const =0
Virtual copy constructor.
const SLIFunction * action
Shortcut to the SLIType default action.
Definition: datum.h:62
Definition: datum.h:33
Datum(const Datum &d)
Definition: datum.h:83
A type-independent container for C++-types.
Definition: token.h:68
unsigned int reference_count_
Definition: datum.h:64
TypedDatum(const TypedDatum< slt > &d)
Definition: datum.h:176
TypedDatum(void)
Definition: datum.h:169
virtual void execute(SLIInterpreter *) const =0
bool is_executable() const
Definition: datum.h:108