NEST  2.6.0,not_revisioned_source_dir@0
functiondatum.h
Go to the documentation of this file.
1 /*
2  * functiondatum.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 FUNCTIONDATUM_H
24 #define FUNCTIONDATUM_H
25 /*
26  Datum class for SLI builtin functions.
27 */
28 
29 #include "datum.h"
30 #include "interpret.h"
31 #include "slifunction.h"
32 #include "allocator.h"
33 /*
34  Each SLI command is represented by a derived class of class SLIFunction.
35  For each command, the constructor of the interpreter must then create
36  a SLIDatum object from a given name (e.g. "add") and a const & to
37  an instance of the derived SLIFunction (e.g. AddFunction). This new
38  datum object must then be registered in the dictionary (hopefully
39  by the same name as before).
40  */
41 
42 class FunctionDatum: public TypedDatum<&SLIInterpreter::Functiontype>
43 {
44  static sli::pool memory;
45 
47 
48  Datum * clone(void) const
49  {
50  return new FunctionDatum(*this);
51  }
52 
54  {
56  return this;
57  }
58 
59  SLIFunction const & operator=(SLIFunction const &f)
60  {
61  std::cerr << "Warning: Definition of FunctionDatum ("<<name<<") changed!!\n";
62 
63  action= &f;
64  return f;
65  }
66 
67 public:
69  :TypedDatum<&SLIInterpreter::Functiontype>(fd),name(fd.name)
70  {set_executable();}
71 
72  FunctionDatum(Name const &n, SLIFunction const *f)
73  : TypedDatum<&SLIInterpreter::Functiontype>(), name(n)
74  {
78  action=f;
80  }
81 
82 
83  void print(std::ostream& o) const
84  {
85  o << '-' << name << '-';
86  }
87 
88  void pprint(std::ostream& o) const
89  {
90  print(o);
91  }
92 
93  void info(std::ostream &out) const
94  {
95  out << "FunctionDatum::info\n";
96  out << "name = " << name << std::endl;
97  }
98 
99  bool equals(Datum const *dat) const
100  {
101  const FunctionDatum
102  *fd=dynamic_cast<FunctionDatum * >(const_cast< Datum *>(dat));
103 
104  if(fd == NULL)
105  return false;
106 
107  return action == fd->action;
108  }
109 
110  const Name & getname(void) const
111  {
112  return name;
113  }
114 
115  void backtrace(SLIInterpreter *, int) const;
116 
117  static void * operator new(size_t size)
118  {
119  if(size != sizeof(FunctionDatum))
120  return ::operator new(size);
121  return memory.alloc();
122  }
123 
124  static void operator delete(void *p, size_t size)
125  {
126  if(p == NULL)
127  return;
128  if(size != sizeof(FunctionDatum))
129  {
130  ::operator delete(p);
131  return;
132  }
133  memory.free(p);
134  }
135 
136 };
137 
138 
139 #endif
140 
141 
void set_executable()
Definition: datum.h:113
void pprint(std::ostream &o) const
Definition: functiondatum.h:88
Definition: datum.h:166
static sli::pool memory
Definition: functiondatum.h:44
FunctionDatum(Name const &n, SLIFunction const *f)
Definition: functiondatum.h:72
Definition: slifunction.h:35
Datum * get_ptr()
Returns a reference counted pointer to the datum, or a new pointer, if the type does not support refe...
Definition: functiondatum.h:53
Represent strings by ints to facilitate fast comparison.
Definition: name.h:53
void backtrace(SLIInterpreter *, int) const
Definition: functiondatum.cc:27
void print(std::ostream &o) const
Definition: functiondatum.h:83
void addReference() const
Definition: datum.h:91
const Name & getname(void) const
Definition: functiondatum.h:110
void info(std::ostream &out) const
Definition: functiondatum.h:93
Definition: interpret.h:69
void * alloc(void)
allocate one element
Definition: allocator.h:137
Definition: functiondatum.h:42
Datum * clone(void) const
Virtual copy constructor.
Definition: functiondatum.h:48
SLIFunction const & operator=(SLIFunction const &f)
Definition: functiondatum.h:59
void free(void *p)
put element back into the pool
Definition: allocator.h:155
FunctionDatum(FunctionDatum const &fd)
Definition: functiondatum.h:68
const Name n("n")
Number of synaptic release sites (int >=0) (Tsodyks2_connection)
Definition: nest_names.h:202
const SLIFunction * action
Shortcut to the SLIType default action.
Definition: datum.h:62
pool is a specialized allocator class for many identical small objects.
Definition: allocator.h:50
Name name
Definition: functiondatum.h:46
Definition: datum.h:33
const Name p("p")
current release probability (Tsodyks2_connection)
Definition: nest_names.h:218
bool equals(Datum const *dat) const
Definition: functiondatum.h:99