HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_ORMContentType.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  * NAME: UT_ORMContentType.h
7  *
8  * COMMENTS:
9  *
10  *
11  */
12 
13 #ifndef __UT_ORMCONTENTTYPE_H__
14 #define __UT_ORMCONTENTTYPE_H__
15 
16 #include "UT_API.h"
17 
18 #include "UT_ORMModelMeta.h"
19 #include "UT_SQLORM.h"
20 
21 /// A simple mechanism to link models to unrelated concepts. When a model is
22 /// added or removed a content-type is inserted. If you have a model that
23 /// applies to another model indirectly this allows that model to be
24 /// added/removed by the foreign key to this content type. It would also allow
25 /// for backtracking as you could lookup the model from the content type.
26 /// The primary purpose is to remove some of the admin work required to have
27 /// two models indirectly related to each other.
28 class UT_API UT_ORMContentType : public UT_ORMModel<UT_ORMContentType>
29 {
31 public:
32  class Meta : public UT_ORMModelMeta
33  {
34  public:
35  using primary_key_t = int;
36 
37  Meta() : UT_ORMModelMeta("sidefx_content_type") {}
38  void doBuild() override;
39  void doPostMigrate() override;
40  void collectMigrations(UT_ORMMigrationBuilder& builder) const override;
41  };
42 
43  UT_ORMContentType(const UT_ORMModelMeta& meta = metaInfo())
44  : UT_ORMModel<UT_ORMContentType>(meta), myNamespace("sidefx")
45  {
46  }
48  : myNamespace(ns), myModelName(model)
49  {
50  }
51 
53  {
54  myModelName = name;
55  }
56  void setNamespace(const UT_StringHolder& ns)
57  {
58  myNamespace = ns;
59  }
60 
61  int id() const
62  {
63  return myID;
64  }
65 
67  {
68  return myNamespace;
69  }
70  const UT_StringHolder& modelName() const
71  {
72  return myModelName;
73  }
74 
76  const UT_ORMModelMeta& meta,
77  UT_ErrorCode& ec,
78  const UT_StringHolder& ns = "sidefx")
79  {
80  using namespace UT::Literal;
81  return filter({"namespace"_f=ns, "model"_f=meta.tableName()}, ec);
82  }
83 
85  const UT_StringHolder& ns,
86  const UT_StringHolder& table_name,
87  UT_ErrorCode& ec)
88  {
89  using namespace UT::Literal;
90  return filter({"namespace"_f = ns, "model"_f = table_name}, ec);
91  }
92 
93 private:
94  int myID = 0;
95  UT_StringHolder myNamespace;
96  UT_StringHolder myModelName;
97 };
98 
99 #endif // __UT_ORMCONTENTTYPE_H__
100 
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
static UT_Optional< UT_ORMContentType > findFromMeta(const UT_ORMModelMeta &meta, UT_ErrorCode &ec, const UT_StringHolder &ns="sidefx")
#define UT_API
Definition: UT_API.h:14
const UT_StringHolder & modelName() const
std::optional< T > UT_Optional
Definition: UT_Optional.h:26
UT_ORMContentType(const UT_ORMModelMeta &meta=metaInfo())
static UT_Optional< UT_ORMContentType > findByNaturalKey(const UT_StringHolder &ns, const UT_StringHolder &table_name, UT_ErrorCode &ec)
const UT_StringHolder & contentTypeNamespace() const
GLuint const GLchar * name
Definition: glcorearb.h:786
std::error_code UT_ErrorCode
Definition: UT_ErrorCode.h:20
const UT_StringHolder & tableName() const
UT_ORMContentType(const UT_StringHolder &ns, const UT_StringHolder &model)
void setNamespace(const UT_StringHolder &ns)
void setModelName(const UT_StringHolder &name)
#define UT_DECLARE_MODEL()
Definition: UT_SQLORM.h:430
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glcorearb.h:1297