HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
COP_CableStructure.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  */
7 
8 #pragma once
9 
10 #include "COP_API.h"
11 
12 #include "COP_Signature.h"
13 
14 #include <UT/UT_Array.h>
15 #include <UT/UT_StringHolder.h>
16 
17 /// This class holds the structure of what flows through a cable. It's an
18 /// ordered collection of fields, each one having a name and a type.
20 {
21 public:
22  /// Each field has a name and a type.
23  struct CableField
24  {
27 
28  /// Required by COP_CableStructure::operator==().
29  bool operator==(const CableField& other) const
30  {
31  return name == other.name && type == other.type;
32  }
33  };
34 
35 public:
37 
38  /// Number of fields in this cable.
39  int getNumberOfFields() const;
40  /// Name of the index-th field in this cable.
41  const UT_StringHolder& getFieldName(int index) const;
42  /// Changes the name of an already-existing field; if the field does not
43  /// exist, returns false without making modifications.
44  bool setFieldName(const UT_StringHolder& name, int index);
45 
46  /// Copies fields names from the other cable.
47  void copyFieldNames(const COP_CableStructure& other);
48 
49  /// All existing fields of this cable structure will be renamed.
50  void renameAllFields(const UT_StringHolder& name);
51 
52  /// Type of the index-th field in this cable.
53  COP_Type getFieldType(int index) const;
54  /// Type of the first field in this cable of the specified name.
55  COP_Type getFieldType(const UT_StringHolder& name) const;
56 
57  /// Index of the field that has the given name.
58  int getFieldIndex(const UT_StringHolder& name, int appearance = 0) const;
59  /// Appearance index fo the field at the given index (this is the 0-based
60  /// index of that field among all fields of the same name).
61  int getFieldAppearance(int index) const;
62 
63  /// Adds a new field to this cable, of the given name and type. The new
64  /// field is added to the end of the current list of fields.
65  void addField(const UT_StringHolder& name, COP_Type type);
66  /// Concatenates this structure with other; fields of other go after all
67  /// current fields of this structure.
68  /// If prefix is not null, every newly-added field's name will be
69  /// prefix.name, where name is name of the original field.
70  void addFields(const COP_CableStructure& other, const char* prefix);
71 
72  /// Removes all fields from this cable structure.
73  void reset();
74 
75  /// Compares with another cable structure; two cable structures are equal if
76  /// all fields have the same name and type.
77  bool operator==(const COP_CableStructure& other) const
78  {
79  return myFields == other.myFields;
80  }
81  bool operator!=(const COP_CableStructure& other) const
82  {
83  return !(myFields == other.myFields);
84  }
85 
86  int64 getMemoryUsage(bool inclusive=false) const
87  {
88  return (inclusive ? sizeof(*this) : 0) + myFields.getMemoryUsage(false);
89  }
90 
91 protected:
92  /// Array of all fields in the cable.
94 };
95 
96 COP_API size_t format(char* buffer, size_t buffer_size,
97  const COP_CableStructure& v);
98 
int64 getMemoryUsage(bool inclusive=false) const
UT_Array< CableField > myFields
Array of all fields in the cable.
const GLdouble * v
Definition: glcorearb.h:837
bool operator==(const CableField &other) const
Required by COP_CableStructure::operator==().
GLuint buffer
Definition: glcorearb.h:660
Each field has a name and a type.
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
GLboolean reset
Definition: glad.h:5138
bool operator==(const COP_CableStructure &other) const
COP_API size_t format(char *buffer, size_t buffer_size, const COP_CableStructure &v)
long long int64
Definition: SYS_Types.h:116
GLuint const GLchar * name
Definition: glcorearb.h:786
COP_Type
Types of basic data that are passed around a COP network.
Definition: COP_Signature.h:17
GLuint index
Definition: glcorearb.h:786
bool operator!=(const COP_CableStructure &other) const
#define COP_API
Definition: COP_API.h:8