RepastHPC  2.3.1
Variable.h
1 /*
2  * Repast for High Performance Computing (Repast HPC)
3  *
4  * Copyright (c) 2010 Argonne National Laboratory
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with
8  * or without modification, are permitted provided that the following
9  * conditions are met:
10  *
11  * Redistributions of source code must retain the above copyright notice,
12  * this list of conditions and the following disclaimer.
13  *
14  * Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution.
17  *
18  * Neither the name of the Argonne National Laboratory nor the names of its
19  * contributors may be used to endorse or promote products derived from
20  * this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
25  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TRUSTEES OR
26  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
32  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  *
34  *
35  * Variable.h
36  *
37  * Created on: Aug 23, 2010
38  * Author: nick
39  */
40 
41 #ifndef VARIABLE_H_
42 #define VARIABLE_H_
43 
44 #include <fstream>
45 #include <vector>
46 
47 namespace repast {
48 
52 class Variable {
53 
54 public:
55  virtual ~Variable() {}
56 
63  virtual void write(size_t index, std::ofstream& out) = 0;
64 
65 
73  virtual void insert(double* array, size_t size) = 0;
74 
75 
83  virtual void insert(int* array, size_t size) = 0;
84 
88  virtual void clear() = 0;
89 
90 };
91 
95 class IntVariable: public Variable {
96 
97 private:
98  std::vector<int> data;
99 
100 public:
101 
102  virtual void write(size_t index, std::ofstream& out);
103  virtual void insert(double* array, size_t size);
104  virtual void insert(int* array, size_t size);
105  virtual void clear() {
106  data.clear();
107  }
108 };
109 
113 class DoubleVariable: public Variable {
114 
115 private:
116  std::vector<double> data;
117 
118 public:
119 
120  virtual void write(size_t index, std::ofstream& out);
121  virtual void insert(double* array, size_t size);
122  virtual void insert(int* array, size_t size);
123  virtual void clear() {
124  data.clear();
125  }
126 };
127 
128 }
129 
130 #endif /* VARIABLE_H_ */
repast::IntVariable::write
virtual void write(size_t index, std::ofstream &out)
Writes the data at the specified index to the specified ofstream.
Definition: Variable.cpp:57
repast::DoubleVariable::write
virtual void write(size_t index, std::ofstream &out)
Writes the data at the specified index to the specified ofstream.
Definition: Variable.cpp:45
repast::Variable
Used in SVDataSet to manage and store the data.
Definition: Variable.h:52
repast::Variable::write
virtual void write(size_t index, std::ofstream &out)=0
Writes the data at the specified index to the specified ofstream.
repast::DoubleVariable::clear
virtual void clear()
Clears this Variable of all the data stored in it.
Definition: Variable.h:123
repast::IntVariable
Used in SVDataSet to manage integer data.
Definition: Variable.h:95
repast::Variable::insert
virtual void insert(double *array, size_t size)=0
Inserts all the doubles in the double array into the collection of data stored in this Variable.
repast::DoubleVariable::insert
virtual void insert(double *array, size_t size)
Inserts all the doubles in the double array into the collection of data stored in this Variable.
Definition: Variable.cpp:48
repast::IntVariable::clear
virtual void clear()
Clears this Variable of all the data stored in it.
Definition: Variable.h:105
repast::DoubleVariable
Used in SVDataSet to manage double data.
Definition: Variable.h:113
repast::IntVariable::insert
virtual void insert(double *array, size_t size)
Inserts all the doubles in the double array into the collection of data stored in this Variable.
Definition: Variable.cpp:63
repast::Variable::clear
virtual void clear()=0
Clears this Variable of all the data stored in it.