NEST  2.6.0,not_revisioned_source_dir@0
triedatum.h
Go to the documentation of this file.
1 /*
2  * triedatum.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 TYPEDFUNCTIONDATUM_H
24 #define TYPEDFUNCTIONDATUM_H
25 #include <typeinfo>
26 #include "slifunction.h"
27 #include "interpret.h"
28 #include "typechk.h"
29 #include "allocator.h"
30 #include "datum.h"
31 
32 class TrieDatum: public TypedDatum<&SLIInterpreter::Trietype>
33 {
34  protected:
35  static sli::pool memory;
36  private:
39 
40  Datum * clone(void) const
41  {
42  return new TrieDatum(*this);
43  }
44 
46  {
48  return this;
49  }
50 
51 public:
52  TrieDatum(TrieDatum const &fd)
53  :TypedDatum<&SLIInterpreter::Trietype>(fd),
54  name(fd.name),tree(fd.tree)
55  {set_executable();}
56 
57  TrieDatum(Name const &n)
58  :name(n), tree() {set_executable();}
59 
60  TrieDatum(Name const &n, const TokenArray &ta)
61  :name(n), tree(ta) {set_executable();}
62 
63 
64  void print(std::ostream& o) const
65  {
66  o << '+' << name << '+';
67  }
68 
69  void pprint(std::ostream& o) const
70  {
71  print(o);
72  }
73 
74  void info(std::ostream &out) const
75  {
76  pprint(out);
77  out << "\nVariants are:" << std::endl;
78  tree.info(out);
79  }
80 
81  bool equals(Datum const *) const;
82 
83  const Name & getname(void) const
84  {
85  return name;
86  }
87 
88  void insert(const TypeArray &a, const Token &t)
89  {
90  tree.insert(a,t);
91  }
92 
93  void insert_move(const TypeArray &a, Token &t)
94  {
95  tree.insert_move(a,t);
96  }
97 
98  const Token& lookup(const TokenStack &s) const
99  {
100  return tree.lookup(s);
101  }
102 
103  TypeTrie& get(void)
104  {
105  return tree;
106  }
107 
108  static void * operator new(size_t size)
109  {
110  if(size != memory.size_of())
111  return ::operator new(size);
112  return memory.alloc();
113  }
114 
115  static void operator delete(void *p, size_t size)
116  {
117  if(p == NULL)
118  return;
119  if(size != memory.size_of())
120  {
121  ::operator delete(p);
122  return;
123  }
124  memory.free(p);
125  }
126 
127 };
128 
129 
130 #endif
size_t size_of(void) const
Definition: allocator.h:128
void set_executable()
Definition: datum.h:113
const Name & getname(void) const
Definition: triedatum.h:83
Definition: datum.h:166
TypeTrie tree
Definition: triedatum.h:38
Definition: tokenstack.h:38
TrieDatum(Name const &n)
Definition: triedatum.h:57
Represent strings by ints to facilitate fast comparison.
Definition: name.h:53
Definition: tokenarray.h:62
void addReference() const
Definition: datum.h:91
const Name a("a")
Specific to Brette & Gerstner 2005 (aeif_cond-*)
Definition: nest_names.h:41
void print(std::ostream &o) const
Definition: triedatum.h:64
Name name
Definition: triedatum.h:37
const Token & lookup(const TokenStack &st) const
Definition: typechk.h:178
Definition: typechk.h:70
Definition: interpret.h:69
void * alloc(void)
allocate one element
Definition: allocator.h:137
Definition: triedatum.h:32
void free(void *p)
put element back into the pool
Definition: allocator.h:155
const Token & lookup(const TokenStack &s) const
Definition: triedatum.h:98
TrieDatum(Name const &n, const TokenArray &ta)
Definition: triedatum.h:60
Datum * get_ptr()
Returns a reference counted pointer to the datum, or a new pointer, if the type does not support refe...
Definition: triedatum.h:45
void info(std::ostream &) const
Definition: typechk.cc:276
const Name n("n")
Number of synaptic release sites (int >=0) (Tsodyks2_connection)
Definition: nest_names.h:202
void insert_move(const TypeArray &, Token &)
Definition: typechk.cc:201
void insert(const TypeArray &a, const Token &t)
Definition: triedatum.h:88
pool is a specialized allocator class for many identical small objects.
Definition: allocator.h:50
Definition: datum.h:33
void insert(const TypeArray &a, const Token &t)
Definition: typechk.h:142
bool equals(Datum const *) const
Definition: triedatum.cc:28
A type-independent container for C++-types.
Definition: token.h:68
static sli::pool memory
Definition: triedatum.h:35
std::vector< Name > TypeArray
Definition: typearray.h:30
Datum * clone(void) const
Virtual copy constructor.
Definition: triedatum.h:40
const Name p("p")
current release probability (Tsodyks2_connection)
Definition: nest_names.h:218
void insert_move(const TypeArray &a, Token &t)
Definition: triedatum.h:93
void info(std::ostream &out) const
Definition: triedatum.h:74
TrieDatum(TrieDatum const &fd)
Definition: triedatum.h:52
void pprint(std::ostream &o) const
Definition: triedatum.h:69