NEST  2.6.0,not_revisioned_source_dir@0
numericdatum.h
Go to the documentation of this file.
1 /*
2  * numericdatum.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 NUMERICDATUM_H
24 #define NUMERICDATUM_H
25 /*
26  Datum template for numeric data types
27 */
28 
29 #include "genericdatum.h"
30 #include "allocator.h"
31 
32 
33 
34 // prefixed all references to members of GenericDatum with this->,
35 // since HP's aCC otherwise complains about them not being declared
36 // according to ISO Standard Sec. 14.6.2(3) [temp.dep]
37 // HEP, 2001-08-08
38 
39 template<class D, SLIType *slt>
40 class NumericDatum: public GenericDatum<D,slt>
41 {
42  protected:
43  static sli::pool memory;
45 
46  private:
47  Datum *clone(void) const
48  {
49  return new NumericDatum<D,slt>(*this);
50  }
51 
52 public:
53 
54  NumericDatum() { d = (D) 0;}
55  NumericDatum(const D& d_s) {d=d_s;}
56  virtual ~NumericDatum() {}
57 
58  operator D() const
59  {return d;}
60 
61  operator D& ()
62  {return d;}
63 
64  void input_form(std::ostream &) const;
65  void pprint(std::ostream &) const;
66 
67 
68  static void * operator new(size_t size)
69  {
70  if(size != memory.size_of())
71  return ::operator new(size);
72  return memory.alloc();
73  }
74 
75  static void operator delete(void *p, size_t size)
76  {
77  if(p == NULL)
78  return;
79  if(size != memory.size_of())
80  {
81  ::operator delete(p);
82  return;
83  }
84  memory.free(p);
85  }
86 
87 };
88 
89 #endif
size_t size_of(void) const
Definition: allocator.h:128
Definition: genericdatum.h:35
void input_form(std::ostream &) const
Definition: numericdatum_impl.h:29
virtual ~NumericDatum()
Definition: numericdatum.h:56
Datum * clone(void) const
Virtual copy constructor.
Definition: numericdatum.h:47
sli::pool memory
Definition: doubledatum.h:48
void pprint(std::ostream &) const
Definition: numericdatum_impl.h:35
D d
Definition: genericdatum.h:44
static sli::pool memory
Definition: numericdatum.h:43
NumericDatum(const D &d_s)
Definition: numericdatum.h:55
NumericDatum()
Definition: numericdatum.h:54
void * alloc(void)
allocate one element
Definition: allocator.h:137
void free(void *p)
put element back into the pool
Definition: allocator.h:155
Definition: numericdatum.h:40
pool is a specialized allocator class for many identical small objects.
Definition: allocator.h:50
Definition: datum.h:33
const Name p("p")
current release probability (Tsodyks2_connection)
Definition: nest_names.h:218