CFx SDK Documentation  2022 SP0
daiAccessDefines.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2018, Open Design Alliance (the "Alliance").
3 // All rights reserved.
4 //
5 // This software and its documentation and related materials are owned by
6 // the Alliance. The software may only be incorporated into application
7 // programs owned by members of the Alliance, subject to a signed
8 // Membership Agreement and Supplemental Software License Agreement with the
9 // Alliance. The structure and organization of this software are the valuable
10 // trade secrets of the Alliance and its suppliers. The software is also
11 // protected by copyright law and international treaty provisions. Application
12 // programs incorporating this software must include the following statement
13 // with their copyright notices:
14 //
15 // This application incorporates Teigha(R) software pursuant to a license
16 // agreement with Open Design Alliance.
17 // Teigha(R) Copyright (C) 2002-2018 by Open Design Alliance.
18 // All rights reserved.
19 //
20 // By use of this software, its documentation or related materials, you
21 // acknowledge and accept the above terms.
23 
24 #ifndef _DAI_ACCESSS_DEFINES_H_
25 #define _DAI_ACCESSS_DEFINES_H_
26 
27 #include "daiModel.h"
28 #include "daiError/daiException.h"
29 
30 namespace OdDAI
31 {
33  {
37  };
38 
39 
40  inline void checkReadMode(const Model* model, const char* functionName, NullModelAction nullModelAction = exceptionAction)
41  {
42  if (model == NULL)
43  {
44  switch (nullModelAction)
45  {
46  case exceptionAction:
47  {
48  throw DaiException(sdaiMO_NVLD, "SDAI-model invalid", functionName);
49  }
50  break;
52  {
53  ODA_ASSERT_ONCE(0 && "Model is null. Abnoraml situation. Try to fix it yourself.");
54  return;
55  }
56  break;
58  {
59  return;
60  }
61  break;
62  }
63  }
64 
65  if (model->mode() == Access_type_unset)
66  {
67  throw DaiException(sdaiMX_NDEF, "SDAI-model access not defined", functionName);
68  }
69  }
70 
71  inline void checkWriteMode(const Model* model, const char* functionName, NullModelAction nullModelAction = exceptionAction)
72  {
73  if (model == NULL)
74  {
75  switch (nullModelAction)
76  {
77  case exceptionAction:
78  {
79  throw DaiException(sdaiMO_NVLD, "SDAI-model invalid", functionName);
80  }
81  break;
83  {
84  ODA_ASSERT_ONCE(0 && "Model is null. Abnoraml situation. Try to fix it yourself.");
85  return;
86  }
87  break;
89  {
90  return;
91  }
92  break;
93  }
94  }
95 
96  if (model->mode() != sdaiRW)
97  {
98  throw DaiException(sdaiMX_NRW, "SDAI-model access not read-write", functionName);
99  }
100  }
101 
102 
103  inline void checkReadModePtr(const ModelPtr& model, const char* functionName, NullModelAction modelAction = exceptionAction)
104  {
105  checkReadMode(model.get(), functionName, modelAction);
106  }
107 
108  inline void checkWriteModePtr(const ModelPtr& model, const char* functionName, NullModelAction modelAction = exceptionAction)
109  {
110  checkWriteMode(model.get(), functionName, modelAction);
111  }
112 
113 #define DAI_ENTITY_ACCESSORS_GET_CHECK() checkReadModePtr(owningModel(), TD_FUNC, silentApproveAccessAction)
114 #define DAI_ENTITY_ACCESSORS_SET_CHECK() checkWriteModePtr(owningModel(), TD_FUNC, silentApproveAccessAction)
115 
116 #define DAI_ENTITY_GET_ATTR_CHECK() checkReadModePtr(owningModel(), TD_FUNC, silentApproveAccessAction)
117 #define DAI_ENTITY_PUT_ATTR_CHECK() checkWriteModePtr(owningModel(), TD_FUNC, silentApproveAccessAction)
118 #define DAI_ENTITY_TEST_ATTR_CHECK() checkReadModePtr(owningModel(), TD_FUNC, silentApproveAccessAction)
119 #define DAI_ENTITY_UNSET_ATTR_CHECK() checkWriteModePtr(owningModel(), TD_FUNC, silentApproveAccessAction)
120 
121 #define DAI_ENTITY_GET_ATTR_DEF_CHECK() checkReadModePtr(owningModel(), TD_FUNC, silentApproveAccessAction)
122 #define DAI_ENTITY_PUT_ATTR_DEF_CHECK() checkWriteModePtr(owningModel(), TD_FUNC, silentApproveAccessAction)
123 #define DAI_ENTITY_TEST_ATTR_DEF_CHECK() checkReadModePtr(owningModel(), TD_FUNC, silentApproveAccessAction)
124 #define DAI_ENTITY_UNSET_ATTR_DEF_CHECK() checkWriteModePtr(owningModel(), TD_FUNC, silentApproveAccessAction)
125 
126 #define DAI_ENTITY_IN_FIELDS_CHECK() checkReadModePtr(owningModel(), TD_FUNC, silentApproveAccessAction)
127 #define DAI_ENTITY_OUT_FIELDS_CHECK() checkWriteModePtr(owningModel(), TD_FUNC, silentApproveAccessAction)
128 
129 #define DAI_ENTITY_SET_INVERSE_COUNTER_PARTS_CHECK() checkWriteModePtr(owningModel(), TD_FUNC, assertApproveAccessAction)
130 
131 #define DAI_MODEL_TRY_READ() checkReadMode(this, TD_FUNC)
132 #define DAI_MODEL_TRY_WRITE() checkWriteMode(this, TD_FUNC)
133 }
134 
135 
136 #endif
137 
#define ODA_ASSERT_ONCE(exp)
Definition: DebugStuff.h:51
#define NULL
Definition: GsProperties.h:177
SdaiAccessMode mode() const
const T * get() const
Definition: SmartPtr.h:326
#define sdaiMX_NDEF
Definition: daiErrorId.h:53
#define sdaiMO_NVLD
Definition: daiErrorId.h:50
#define sdaiMX_NRW
Definition: daiErrorId.h:52
void checkReadModePtr(const ModelPtr &model, const char *functionName, NullModelAction modelAction=exceptionAction)
void checkReadMode(const Model *model, const char *functionName, NullModelAction nullModelAction=exceptionAction)
void checkWriteModePtr(const ModelPtr &model, const char *functionName, NullModelAction modelAction=exceptionAction)
void checkWriteMode(const Model *model, const char *functionName, NullModelAction nullModelAction=exceptionAction)
@ exceptionAction
@ silentApproveAccessAction
@ assertApproveAccessAction
@ Access_type_unset
Definition: sdai.h:298
@ sdaiRW
Definition: sdai.h:298