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 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
|
/*****************************************************************************
*
* 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 ATTRIBUTEGROUP_H
#define ATTRIBUTEGROUP_H
#include <state_exports.h>
#include <vector>
#include <string>
#include <visitstream.h>
#include <vectortypes.h>
#include <VisItException.h>
#include <MapNode.h>
#include <JSONNode.h>
// Forward declaration
class AttributeGroup;
class Connection;
class DataNode;
// ****************************************************************************
// Class: AttributeGroup
//
// Purpose:
// This is the base class for state objects that can be transmitted
// across a connection.
//
// Notes:
//
// Programmer: Brad Whitlock
// Creation: Fri Aug 4 16:37:48 PST 2000
//
// Modifications:
// Jeremy Meredith, Mon Feb 26 16:02:31 PST 2001
// Added unsigned chars.
//
// Brad Whitlock, Tue Oct 9 15:36:19 PST 2001
// Added methods for returning the type name and copying objects.
//
// Jeremy Meredith, Wed May 8 10:56:32 PDT 2002
// Added methods needed for keyframing, mostly relating
// to individual fields.
//
// Eric Brugger, Fri Nov 15 12:48:02 PST 2002
// Add the method Interpolate.
//
// Brad Whitlock, Fri Dec 27 15:11:40 PST 2002
// I added a few more methods to the typeInfo class to get rid of some
// memory leaks in purify.
//
// Jeremy Meredith, Thu Jan 16 12:42:22 PST 2003
// Changed things a bit for keyframing enhancements.
//
// Brad Whitlock, Fri Mar 21 09:44:44 PDT 2003
// I added a virtual function that can modify the DataNode that is read
// from the config file so that we can handle old versions. I also added
// a static method for version comparison.
//
// Brad Whitlock, Tue May 20 08:54:38 PDT 2003
// I added a second argument to CreateNode.
//
// Brad Whitlock, Wed Dec 17 11:51:40 PDT 2003
// I added a third argument to CreateNode.
//
// Brad Whitlock, Thu Dec 9 15:04:41 PST 2004
// I added FieldType_variablename.
//
// Hank Childs, Fri Jan 28 15:36:03 PST 2005
// Re-inherit exceptions from VisItException.
//
// Brad Whitlock, Tue May 3 11:05:15 PDT 2005
// I added SelectField, SelectFields and made Select private.
//
// Kathleen Bonnell, Thu Mar 22 16:43:38 PDT 2007
// Added FieldType_scalemode.
//
// Brad Whitlock, Tue Jan 6 13:47:25 PST 2009
// I added support for including MapNode objects as fields.
//
// Mark C. Miller, Wed Aug 26 11:11:19 PDT 2009
// Added _private_tmfs_t type for derived state object constructors.
//
// Mark C. Miller, Mon Aug 31 14:07:18 PDT 2009
// Added a generic exception class for state object failures.
//
// Kathleen Biagas, Wed Dec 21 07:47:58 PST 2016
// Added glyphtype field.
//
// ****************************************************************************
class STATE_API AttributeGroup
{
public:
enum FieldType {
FieldType_unknown,
FieldType_bool,
FieldType_boolVector,
FieldType_char,
FieldType_charArray,
FieldType_charVector,
FieldType_uchar,
FieldType_ucharArray,
FieldType_ucharVector,
FieldType_int,
FieldType_intArray,
FieldType_intVector,
FieldType_long,
FieldType_longArray,
FieldType_longVector,
FieldType_float,
FieldType_floatArray,
FieldType_floatVector,
FieldType_double,
FieldType_doubleArray,
FieldType_doubleVector,
FieldType_string,
FieldType_stringArray,
FieldType_stringVector,
FieldType_colortable,
FieldType_color,
FieldType_opacity,
FieldType_linestyle,
FieldType_linewidth,
FieldType_variablename,
FieldType_att,
FieldType_attVector,
FieldType_enum,
FieldType_scalemode,
FieldType_MapNode,
FieldType_glyphtype
};
enum {
AttributeGroupType = MapNode::ID__LAST,
AttributeGroupListType,
AttributeGroupVectorType,
ID__LAST
} AttributeGroupEnumType;
// This type is used only by code-generated state objects
// which are themselves derived from other code-generated
// state objects. We define this (silly) type to prevent
// any possibility of collision between a user-defined
// constructor requiring a single char* or std::string
// argument and constructors needed to support derived
// state objects.
typedef struct _private_tmfs_t {
const char *tmfs;
} private_tmfs_t;
public:
AttributeGroup(const char *formatString);
virtual ~AttributeGroup();
void Write(Connection &conn);
void Read(Connection &conn);
int CalculateMessageSize(Connection &conn);
void Write(MapNode& map);
void WriteAPI(MapNode& map);
void WriteMetaData(MapNode& map);
//void Read(MapNode& map);
void Write(JSONNode& map);
void WriteAPI(JSONNode& map);
void WriteMetaData(JSONNode& map);
//void Read(JSONNode& map);
void SetSendMetaInformation(bool send) { sendMetaInformation = send; }
bool GetSendMetaInformation() { return sendMetaInformation; }
int NumAttributes() const;
int NumAttributesSelected() const;
bool IsSelected(int i) const;
void SetGuido(int);
int GetGuido();
// Selects all of the attributes in the AttributeGroup
virtual void SelectAll() = 0;
void SelectField(int);
void SelectFields(const std::vector<int> &);
void UnSelectAll();
virtual bool CreateNode(DataNode *node, bool, bool);
virtual void SetFromNode(DataNode *node);
virtual void ProcessOldVersions(DataNode *node, const char *configVersion);
STATE_API friend ostream& operator<<(ostream& os, const AttributeGroup&);
virtual bool CopyAttributes(const AttributeGroup *atts);
virtual void InterpolateConst(const AttributeGroup *atts1,
const AttributeGroup *atts2, double f);
virtual void InterpolateLinear(const AttributeGroup *atts1,
const AttributeGroup *atts2, double f);
virtual bool EqualTo(const AttributeGroup *atts) const;
virtual const std::string TypeName() const;
virtual std::string GetFieldName(int index) const;
int FieldNameToIndex(const std::string &fieldName) const;
virtual FieldType GetFieldType(int index) const;
virtual std::string GetFieldTypeName(int index) const;
virtual bool FieldsEqual(int index, const AttributeGroup*) const;
// Generic methods for setting fields.
virtual bool SetValue(const std::string &name, const char &value);
virtual bool SetValue(const std::string &name, const unsigned char &value);
virtual bool SetValue(const std::string &name, const int &value);
virtual bool SetValue(const std::string &name, const long &value);
virtual bool SetValue(const std::string &name, const float &value);
virtual bool SetValue(const std::string &name, const double &value);
virtual bool SetValue(const std::string &name, const std::string &value);
virtual bool SetValue(const std::string &name, const bool &value);
virtual bool SetValue(const std::string &name, const char *value, int len);
virtual bool SetValue(const std::string &name, const unsigned char *value, int len);
virtual bool SetValue(const std::string &name, const int *value, int len);
virtual bool SetValue(const std::string &name, const long *value, int len);
virtual bool SetValue(const std::string &name, const float *value, int len);
virtual bool SetValue(const std::string &name, const double *value, int len);
virtual bool SetValue(const std::string &name, const std::string *value, int len);
virtual bool SetValue(const std::string &name, const bool *value, int len);
virtual bool SetValue(const std::string &name, const charVector &value);
virtual bool SetValue(const std::string &name, const unsignedCharVector &value);
virtual bool SetValue(const std::string &name, const intVector &value);
virtual bool SetValue(const std::string &name, const longVector &value);
virtual bool SetValue(const std::string &name, const floatVector &value);
virtual bool SetValue(const std::string &name, const doubleVector &value);
virtual bool SetValue(const std::string &name, const stringVector &value);
virtual bool SetValue(const std::string &name, const boolVector &value);
virtual bool SetValue(const std::string &name, const MapNode &value);
// Generic methods for getting fields.
virtual bool GetValue(const std::string &name, char &value);
virtual bool GetValue(const std::string &name, unsigned char &value);
virtual bool GetValue(const std::string &name, int &value);
virtual bool GetValue(const std::string &name, long &value);
virtual bool GetValue(const std::string &name, float &value);
virtual bool GetValue(const std::string &name, double &value);
virtual bool GetValue(const std::string &name, std::string &value);
virtual bool GetValue(const std::string &name, bool &value);
virtual bool GetValue(const std::string &name, char **value, int &len);
virtual bool GetValue(const std::string &name, unsigned char **value, int &len);
virtual bool GetValue(const std::string &name, int **value, int &len);
virtual bool GetValue(const std::string &name, long **value, int &len);
virtual bool GetValue(const std::string &name, float **value, int &len);
virtual bool GetValue(const std::string &name, double **value, int &len);
virtual bool GetValue(const std::string &name, std::string **value, int &len);
virtual bool GetValue(const std::string &name, bool **value, int &len);
virtual bool GetValue(const std::string &name, charVector &value);
virtual bool GetValue(const std::string &name, unsignedCharVector &value);
virtual bool GetValue(const std::string &name, intVector &value);
virtual bool GetValue(const std::string &name, longVector &value);
virtual bool GetValue(const std::string &name, floatVector &value);
virtual bool GetValue(const std::string &name, doubleVector &value);
virtual bool GetValue(const std::string &name, stringVector &value);
virtual bool GetValue(const std::string &name, boolVector &value);
virtual bool GetValue(const std::string &name, MapNode &value);
static bool VersionLessThan(const char *configVersion, const char *version);
protected:
void Select(int index, void *address, int length = 0);
// Used to instantiate a new sub attribute.
virtual AttributeGroup *CreateSubAttributeGroup(int attrId);
// These are used to declare the AttributeGroup's component types.
void DeclareChar();
void DeclareUnsignedChar();
void DeclareInt();
void DeclareLong();
void DeclareFloat();
void DeclareDouble();
void DeclareString();
void DeclareAttributeGroup();
void DeclareBool();
void DeclareListChar();
void DeclareListUnsignedChar();
void DeclareListInt();
void DeclareListLong();
void DeclareListFloat();
void DeclareListDouble();
void DeclareListString();
void DeclareListAttributeGroup();
void DeclareListBool();
void DeclareVectorChar();
void DeclareVectorUnsignedChar();
void DeclareVectorInt();
void DeclareVectorLong();
void DeclareVectorFloat();
void DeclareVectorDouble();
void DeclareVectorString();
void DeclareVectorAttributeGroup();
void DeclareVectorBool();
void DeclareMapNode();
private:
class STATE_API typeInfo
{
public:
typeInfo();
typeInfo(const typeInfo &);
typeInfo(unsigned char tcode);
virtual ~typeInfo();
void operator = (const typeInfo &);
void *address;
int length;
unsigned char typeCode;
bool selected;
};
typedef std::vector<typeInfo> typeInfoVector;
// Support methods
void CreateTypeMap(const char *formatString);
void WriteType(Connection &conn, typeInfo &info);
void ReadType(Connection &conn, int attrId, typeInfo &info);
void WriteType(MapNode &map, int attrId, typeInfo &info);
void WriteAPI(MapNode &map, int attrId,typeInfo &info);
//void ReadType(MapNode &map, int attrId, typeInfo &info);
void WriteMetaData(MapNode &map, int attrId,typeInfo &info);
void WriteType(JSONNode &map, int attrId, typeInfo &info);
void WriteAPI(JSONNode &map, int attrId,typeInfo &info);
//void ReadType(JSONNode &map, int attrId, typeInfo &info);
void WriteMetaData(JSONNode &map, int attrId,typeInfo &info);
private:
typeInfoVector typeMap; // Holds typemap for the whole class
int guido;
bool sendMetaInformation; //tells connection whether to send meta information
//as well.
};
STATE_API ostream& operator<<(ostream& os, const AttributeGroup&);
typedef std::vector<AttributeGroup *> AttributeGroupVector;
// An exception class
class STATE_API BadDeclareFormatString : public VisItException { };
class STATE_API StateObjectException : public VisItException { };
#endif
|