HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SIM_RootDataId.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 #ifndef __SIM_RootDataId_h__
9 #define __SIM_RootDataId_h__
10 
11 #include "SIM_API.h"
12 
13 #include <UT/UT_Format.h>
14 #include <UT/UT_StringHolder.h>
15 #include <SYS/SYS_Hash.h>
16 
18 {
19 public:
20  SIM_RootDataId() { myId = -1; }
21 
22  explicit SIM_RootDataId(exint id) : myId(id) {}
23  explicit SIM_RootDataId(const UT_StringHolder &name) : myId(-1), myName(name) {}
24 
26  { return myName; }
27  int getId() const
28  { return myId; }
29 
30  void clear()
31  { myId = -1; myName = ""; }
32  bool getIsClear() const
33  { return (myId == -1 && !myName.isstring()); }
34 
35  bool operator==(const SIM_RootDataId &other) const
36  {
37  return myId == other.myId && myName == other.myName;
38  }
39 
40  bool operator!=(const SIM_RootDataId &other) const
41  {
42  return myId != other.myId || myName != other.myName;
43  }
44 
46  {
47  SYS_HashType hash = myName.hash();
48  SYShashCombine(hash, myId);
49  return hash;
50  }
51 
52 private:
53  UT_StringHolder myName;
54  exint myId;
55 };
56 
57 inline SYS_HashType hash_value(const SIM_RootDataId &id) { return id.hash(); }
58 
59 inline size_t
60 format(char *buffer, size_t buffer_size, const SIM_RootDataId &id)
61 {
62  UT::Format::Writer writer(buffer, buffer_size);
64  if (id.getName())
65  return f.format(writer, "{0}", {id.getName()});
66  else
67  return f.format(writer, "{0}", {id.getId()});
68 }
69 
70 #endif
SYS_HashType hash_value(const SIM_RootDataId &id)
size_t format(char *buffer, size_t buffer_size, const SIM_RootDataId &id)
int64 exint
Definition: SYS_Types.h:125
std::size_t SYS_HashType
Define the type for hash values.
Definition: SYS_Hash.h:19
UT_StringHolder getName() const
GLfloat f
Definition: glcorearb.h:1926
Definition: core.h:760
PXL_API const char * getName(const ColorSpace *space)
Return the name of the color space.
SYS_HashType hash() const
bool operator!=(const SIM_RootDataId &other) const
GLuint const GLchar * name
Definition: glcorearb.h:786
bool getIsClear() const
#define SIM_API
Definition: SIM_API.h:12
Type-safe formatting, modeled on the Python str.format function.
bool operator==(const SIM_RootDataId &other) const
SIM_RootDataId(const UT_StringHolder &name)
size_t format(W &writer, const char *format, std::initializer_list< ArgValue > args)
SIM_RootDataId(exint id)
int getId() const