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  /// Changes the type of an already-existing field; if the field does not
57  /// exist, returns false without making modifications.
58  bool setFieldType(COP_Type type, int index);
59 
60  /// Index of the field that has the given name.
61  int getFieldIndex(const UT_StringHolder& name, int appearance = 0) const;
62  /// Returns index of the first field that starts with the given name. If
63  /// name of this field is an exact match, full_match is set to true.
64  /// Otherwise, full_match is set to false. If a non-negative index (K) is
65  /// returned and full_match is false, then the field at index K is the first
66  /// one whose name starts with {name}{delimiter}. Returns -1 if no matches
67  /// were found.
68  int getFieldIndexFromPrefix(const UT_StringHolder& name, bool& full_match,
69  char delimiter = '.') const;
70  /// Appearance index fo the field at the given index (this is the 0-based
71  /// index of that field among all fields of the same name).
72  int getFieldAppearance(int index) const;
73 
74  /// Adds a new field to this cable, of the given name and type. The new
75  /// field is added to the end of the current list of fields.
76  void addField(const UT_StringHolder& name, COP_Type type);
77  /// Concatenates this structure with other; fields of other go after all
78  /// current fields of this structure.
79  /// If prefix is not null, every newly-added field's name will be
80  /// prefix.name, where name is name of the original field.
81  void addFields(const COP_CableStructure& other, const char* prefix);
82 
83  /// Removes all fields from this cable structure.
84  void reset();
85 
86  /// Compares with another cable structure; two cable structures are equal if
87  /// all fields have the same name and type.
88  bool operator==(const COP_CableStructure& other) const
89  {
90  return myFields == other.myFields;
91  }
92  bool operator!=(const COP_CableStructure& other) const
93  {
94  return !(myFields == other.myFields);
95  }
96 
97  int64 getMemoryUsage(bool inclusive=false) const
98  {
99  return (inclusive ? sizeof(*this) : 0) + myFields.getMemoryUsage(false);
100  }
101 
102 protected:
103  /// Array of all fields in the cable.
105 };
106 
107 COP_API size_t
108 UTformatBuffer(char* buffer, size_t buffer_size, const COP_CableStructure& v);
109 
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 UTformatBuffer(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