File: DataNode.h

package info (click to toggle)
paraview 5.4.1%2Bdfsg4-3.1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 218,616 kB
  • sloc: cpp: 2,331,508; ansic: 322,365; python: 111,051; xml: 79,203; tcl: 47,013; yacc: 4,877; java: 4,438; perl: 3,238; sh: 2,920; lex: 1,908; f90: 748; makefile: 273; pascal: 228; objc: 83; fortran: 31
file content (246 lines) | stat: -rw-r--r-- 9,878 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/*****************************************************************************
*
* Copyright (c) 2000 - 2017, Lawrence Livermore National Security, LLC
* Produced at the Lawrence Livermore National Laboratory
* LLNL-CODE-442911
* All rights reserved.
*
* This file is  part of VisIt. For  details, see https://visit.llnl.gov/.  The
* full copyright notice is contained in the file COPYRIGHT located at the root
* of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html.
*
* Redistribution  and  use  in  source  and  binary  forms,  with  or  without
* modification, are permitted provided that the following conditions are met:
*
*  - Redistributions of  source code must  retain the above  copyright notice,
*    this list of conditions and the disclaimer below.
*  - Redistributions in binary form must reproduce the above copyright notice,
*    this  list of  conditions  and  the  disclaimer (as noted below)  in  the
*    documentation and/or other materials provided with the distribution.
*  - Neither the name of  the LLNS/LLNL nor the names of  its contributors may
*    be used to endorse or promote products derived from this software without
*    specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT  HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR  IMPLIED WARRANTIES, INCLUDING,  BUT NOT  LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND  FITNESS FOR A PARTICULAR  PURPOSE
* ARE  DISCLAIMED. IN  NO EVENT  SHALL LAWRENCE  LIVERMORE NATIONAL  SECURITY,
* LLC, THE  U.S.  DEPARTMENT OF  ENERGY  OR  CONTRIBUTORS BE  LIABLE  FOR  ANY
* DIRECT,  INDIRECT,   INCIDENTAL,   SPECIAL,   EXEMPLARY,  OR   CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT  LIMITED TO, PROCUREMENT OF  SUBSTITUTE GOODS OR
* SERVICES; LOSS OF  USE, DATA, OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER
* CAUSED  AND  ON  ANY  THEORY  OF  LIABILITY,  WHETHER  IN  CONTRACT,  STRICT
* LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE)  ARISING IN ANY  WAY
* OUT OF THE  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
*****************************************************************************/

#ifndef DATANODE_H
#define DATANODE_H
#include <state_exports.h>
#include <AttributeGroup.h>
#include <visitstream.h>

typedef enum
{
    INTERNAL_NODE = 0,
    CHAR_NODE, UNSIGNED_CHAR_NODE, INT_NODE, LONG_NODE, FLOAT_NODE,
    DOUBLE_NODE, STRING_NODE, BOOL_NODE,
    CHAR_ARRAY_NODE, UNSIGNED_CHAR_ARRAY_NODE, INT_ARRAY_NODE,
    LONG_ARRAY_NODE, FLOAT_ARRAY_NODE,
    DOUBLE_ARRAY_NODE, STRING_ARRAY_NODE, BOOL_ARRAY_NODE,
    CHAR_VECTOR_NODE, UNSIGNED_CHAR_VECTOR_NODE, INT_VECTOR_NODE,
    LONG_VECTOR_NODE, FLOAT_VECTOR_NODE,
    DOUBLE_VECTOR_NODE, STRING_VECTOR_NODE, BOOL_VECTOR_NODE,
    MAP_NODE_NODE
} NodeTypeEnum;

// ****************************************************************************
// Class: DataNode
//
// Purpose:
//   This class contains a tree structure that is the basis of the
//   configuration file when it is in memory.
//
// Notes:      
//
// Programmer: Brad Whitlock
// Creation:   Thu Sep 28 10:14:49 PDT 2000
//
// Modifications:
//   Jeremy Meredith, Mon Feb 26 16:01:09 PST 2001
//   Added unsigned chars.
//
//   Brad Whitlock, Fri Mar 21 10:43:22 PDT 2003
//   I added methods to set the DataNode's data so it can be
//   transformed to a new type.
//
//   Brad Whitlock, Mon Feb 2 15:36:49 PST 2004
//   Added an optional argument to RemoveNode.
//
//   Eric Brugger, Tue Mar 27 15:57:03 PDT 2007
//   Added an additional RemoveNode method that takes a DataNode as an
//   argument.
//
//   Brad Whitlock, Thu Feb 14 14:49:19 PST 2008
//   Added SearchForNode and make GetNode not recurse.
//
//   Brad Whitlock, Tue Apr 22 12:14:38 PDT 2008
//   Added a Print method for debugging.
//
//    Kathleen Biagas, Fri Jun 17 16:41:27 PDT 2011
//    Add MapNode node.
//
//   Burlen Loring, Wed Jul 16 18:38:55 PDT 2014
//   Added cast helper methods to catch invalid casts that lead
//   to undefined behavior
//
// ****************************************************************************

class STATE_API DataNode
{
public:
    // Internal node constructor
    DataNode(const std::string &name);

    // Single element constructors
    DataNode(const std::string &name, char val);
    DataNode(const std::string &name, unsigned char val);
    DataNode(const std::string &name, int val);
    DataNode(const std::string &name, long val);
    DataNode(const std::string &name, float val);
    DataNode(const std::string &name, double val);
    DataNode(const std::string &name, const std::string &val);
    DataNode(const std::string &name, bool val);

    // Array constructors
    DataNode(const std::string &name, const char *vals, int len);
    DataNode(const std::string &name, const unsigned char *vals, int len);
    DataNode(const std::string &name, const int *vals, int len);
    DataNode(const std::string &name, const long *vals, int len);
    DataNode(const std::string &name, const float *vals, int len);
    DataNode(const std::string &name, const double *val, int len);
    DataNode(const std::string &name, const std::string *vals, int len);
    DataNode(const std::string &name, const bool *vals, int len);

    // Vector constructors
    DataNode(const std::string &name, const charVector &vec);
    DataNode(const std::string &name, const unsignedCharVector &vec);
    DataNode(const std::string &name, const intVector &vec);
    DataNode(const std::string &name, const longVector &vec);
    DataNode(const std::string &name, const floatVector &vec);
    DataNode(const std::string &name, const doubleVector &vec);
    DataNode(const std::string &name, const stringVector &vec);

    DataNode(const std::string &name, const MapNode &val);

    ~DataNode();

    // Functions to return the data as a particular type.
    char               AsChar() const;
    unsigned char      AsUnsignedChar() const;
    int                AsInt()  const;
    long               AsLong() const;
    float              AsFloat() const;
    double             AsDouble() const;
    const std::string &AsString() const;
    bool               AsBool() const;

    const char          *AsCharArray() const;
    const unsigned char *AsUnsignedCharArray() const;
    const int           *AsIntArray()  const;
    const long          *AsLongArray() const;
    const float         *AsFloatArray() const;
    const double        *AsDoubleArray() const;
    const std::string   *AsStringArray() const;
    const bool          *AsBoolArray() const;

    const charVector          &AsCharVector() const;
    const unsignedCharVector  &AsUnsignedCharVector() const;
    const intVector           &AsIntVector()  const;
    const longVector          &AsLongVector() const;
    const floatVector         &AsFloatVector() const;
    const doubleVector        &AsDoubleVector() const;
    const stringVector        &AsStringVector() const;

    const MapNode             &AsMapNode() const;

    void SetChar(char val);
    void SetUnsignedChar(unsigned char val);
    void SetInt(int val);
    void SetLong(long val);
    void SetFloat(float val);
    void SetDouble(double val);
    void SetString(const std::string &val);
    void SetBool(bool val);
    void SetCharArray(const char *vals, int len);
    void SetUnsignedCharArray(const unsigned char *vals, int len);
    void SetIntArray(const int *vals, int len);
    void SetLongArray(const long *vals, int len);
    void SetFloatArray(const float *vals, int len);
    void SetDoubleArray(const double *vals, int len);
    void SetStringArray(const std::string *vals, int len);
    void SetBoolArray(const bool *vals, int len);
    void SetCharVector(const charVector &vec);
    void SetUnsignedCharVector(const unsignedCharVector &vec);
    void SetIntVector(const intVector &vec);
    void SetLongVector(const longVector &vec);
    void SetFloatVector(const floatVector &vec);
    void SetDoubleVector(const doubleVector &vec);
    void SetStringVector(const stringVector &vec);

    void SetMapNode(const MapNode &val);

    // Node operations
    DataNode *GetNode(const std::string &key);
    DataNode *SearchForNode(const std::string &key, DataNode *parentNode = 0);
    void AddNode(DataNode *node);
    void RemoveNode(DataNode *node, bool deleteNode = true);
    void RemoveNode(const std::string &key, bool deleteNode = true);
    void Print(ostream &os, int indent = 0);

    // Functions to return private members.
    const std::string &GetKey() const;
    void SetKey(const std::string &);
    NodeTypeEnum GetNodeType() const;
    int GetLength() const;
    int GetNumChildren() const;
    int GetNumChildObjects() const;
    DataNode **GetChildren();

private:
    DataNode(); // not implemented
    DataNode(const DataNode &); // not implemented
    void operator=(const DataNode &); // not implemented

    void FreeData();

    // Functions to handle validation of casts from void*
    // and the following conversions
    template <typename RetType> RetType AsValue() const;
    template <typename RetType> const RetType &AsClass(RetType &substitute) const;
    template <typename RetType> const RetType *AsArray() const;

    std::string   Key;
    NodeTypeEnum  NodeType;
    int           Length;
    void          *Data;

    // Static members
    static std::string         bogusString;
    static charVector          bogusCharVector;
    static unsignedCharVector  bogusUnsignedCharVector;
    static intVector           bogusIntVector;
    static longVector          bogusLongVector;
    static floatVector         bogusFloatVector;
    static doubleVector        bogusDoubleVector;
    static stringVector        bogusStringVector;
    static MapNode             bogusMapNode;
};

// Utility functions.
const char *NodeTypeName(int e);
NodeTypeEnum GetNodeType(const char *str);

#endif