Flow123d
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
flow123d
src
input
storage.hh
Go to the documentation of this file.
1
/*
2
* storage.hh
3
*
4
* Created on: May 5, 2012
5
* Author: jb
6
*/
7
8
#ifndef STORAGE_HH_
9
#define STORAGE_HH_
10
11
/**
12
* Iterator - like intermediate class for access to the stored values. The storage is a tree where
13
* one node can hold:
14
* - int, double, bool
15
* - pointer to string
16
* - pointer to array of storages
17
* - special state: NULL (no data)
18
* INCLUDE (have to read another file to provide the value, this may be possible only through particular readers)
19
* ...
20
*
21
* json_spirit use boost::variant for storing JSON tree and arrays are stored as vectors of these variants
22
* not pointers to variants. This is probably more effective, but do not allow effective modifications of the
23
* tree and also construction not involving copies is not very intuitive. Therefore we use our own storage and
24
* copy the json_spirit tree into it.
25
*/
26
27
#include <iostream>
28
#include <string>
29
#include <vector>
30
#include "
system/exceptions.hh
"
31
32
33
namespace
Input {
34
35
TYPEDEF_ERR_INFO
( EI_RequestedType,
const
std::string);
36
TYPEDEF_ERR_INFO
( EI_StoredType,
const
std::string);
37
DECLARE_EXCEPTION
(ExcStorageTypeMismatch, <<
"Storage type mismatch. You want value of type "
38
<< EI_RequestedType::qval <<
" but stored is value of type "
39
<< EI_StoredType::qval);
40
41
42
/**
43
* @brief Base class for nodes of a data storage tree.
44
*
45
* This class as well as its descendants is meant for internal usage only as part of the implementation of the input interface.
46
*
47
* The leave nodes of the data storage tree can be of types \p StorageBool, \p StorageInt, \p StorageDouble, and StorageNull.
48
* The branching nodes of the tree are of type StorageArray. The data storage tree serves to store data with structure described
49
* by Input::Type classes. Therefore it provides no way to ask for the type of stored data and an exception \p ExcStorageTypeMismatch
50
* is thrown if you use
51
* getter that do not match actual type of the node. Moreover, the tree can be only created using bottom-up approach and than can
52
* not be modified ( this can change if we want to use same storage for buffered reading of large data). However, we provide a method for
53
* deep copy of any subtree.
54
*
55
* @ingroup input
56
*/
57
class
StorageBase
{
58
public
:
59
virtual
int
get_int
()
const
;
60
virtual
double
get_double
()
const
;
61
virtual
bool
get_bool
()
const
;
62
virtual
const
std::string &
get_string
()
const
;
63
virtual
const
StorageBase
*
get_item
(
const
unsigned
int
index)
const
;
64
virtual
bool
is_null
()
const
=0;
65
virtual
unsigned
int
get_array_size
()
const
;
66
67
virtual
StorageBase
*
deep_copy
()=0;
68
virtual
void
print
(std::ostream &stream,
int
pad=0)
const
=0;
69
70
virtual
~StorageBase
();
71
72
};
73
74
/**
75
* Simple array of heterogeneous values. The values are inserted as pointers
76
* (no copies) that is possibly dangerous, but don't care as the Storage is meant for internal usage only.
77
*/
78
class
StorageArray
:
public
StorageBase
{
79
public
:
80
StorageArray
(
unsigned
int
size);
81
StorageArray
(
const
StorageArray
&);
// deep copy for test purpose
82
void
new_item
(
unsigned
int
index,
StorageBase
* item);
83
virtual
const
StorageBase
*
get_item
(
const
unsigned
int
index)
const
;
84
virtual
unsigned
int
get_array_size
()
const
;
85
virtual
bool
is_null
()
const
;
86
virtual
StorageBase
*
deep_copy
();
87
virtual
void
print
(std::ostream &stream,
int
pad=0)
const
;
88
virtual
~StorageArray
();
89
private
:
90
/// Forbids default constructor to have array set to NULL.
91
StorageArray
();
92
std::vector<StorageBase *>
array_
;
93
};
94
95
96
class
StorageBool
:
public
StorageBase
{
97
public
:
98
StorageBool
(
bool
value);
99
virtual
bool
get_bool
()
const
;
100
virtual
bool
is_null
()
const
;
101
virtual
StorageBase
*
deep_copy
();
102
virtual
void
print
(std::ostream &stream,
int
pad=0)
const
;
103
virtual
~StorageBool
();
104
private
:
105
bool
value_
;
106
};
107
108
class
StorageInt
:
public
StorageBase
{
109
public
:
110
StorageInt
(
int
value);
111
virtual
int
get_int
()
const
;
112
virtual
bool
is_null
()
const
;
113
virtual
StorageBase
*
deep_copy
();
114
virtual
void
print
(std::ostream &stream,
int
pad=0)
const
;
115
virtual
~StorageInt
();
116
117
private
:
118
int
value_
;
119
};
120
121
class
StorageDouble
:
public
StorageBase
{
122
public
:
123
StorageDouble
(
double
value);
124
virtual
double
get_double
()
const
;
125
virtual
bool
is_null
()
const
;
126
virtual
StorageBase
*
deep_copy
();
127
virtual
void
print
(std::ostream &stream,
int
pad=0)
const
;
128
virtual
~StorageDouble
();
129
130
private
:
131
double
value_
;
132
};
133
134
class
StorageString
:
public
StorageBase
{
135
public
:
136
StorageString
(
const
std::string & value);
137
virtual
const
std::string &
get_string
()
const
;
138
virtual
bool
is_null
()
const
;
139
virtual
StorageBase
*
deep_copy
();
140
virtual
void
print
(std::ostream &stream,
int
pad=0)
const
;
141
virtual
~StorageString
();
142
143
private
:
144
std::string
value_
;
145
};
146
147
class
StorageNull
:
public
StorageBase
{
148
virtual
bool
is_null
()
const
;
149
virtual
StorageBase
*
deep_copy
();
150
virtual
void
print
(std::ostream &stream,
int
pad=0)
const
;
151
virtual
~StorageNull
();
152
153
};
154
155
}
// namespace Input
156
157
#endif
/* STORAGE_HH_ */
158
159
Generated on Thu May 29 2014 23:14:48 for Flow123d by
1.8.4