CFx SDK Documentation  2022 SP0
daiApiUtils.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2019, 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 valueuable
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 Open Design Alliance software pursuant to a license
16 // agreement with Open Design Alliance.
17 // Open Design Alliance Copyright (C) 2002-2019 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_API_UTILS_H_
25 #define _DAI_API_UTILS_H_
26 
27 #include "OdaCommon.h"
28 #include "daiBuildOptions.h"
29 
30 #include "daiRepository.h"
31 #include "daiModel.h"
32 
33 #include "RxObject.h"
34 
35 #include "OdString.h"
36 #include "SmartPtr.h"
37 
38 #include "sdai.h"
39 
40 namespace OdDAI
41 {
42  namespace Utils
43  {
45  {
46  public:
48  : m_model(model)
49  {
50  ODA_ASSERT(!model.isNull() && model->mode() != Access_type_unset);
51  }
52 
53  virtual ~ModelProvider()
54  {
55  if (m_model.isNull())
56  {
57  return;
58  }
59 
60  //auto close model
61  m_model->closeModel();
62  }
63 
64  template <class TModel>
66  {
67  if (m_model.isNull())
68  {
69  return OdSmartPtr<TModel>();
70  }
71 
72  return TModel::cast(m_model);
73  }
74 
75  private:
76  ModelPtr m_model;
77  };
78 
80  : public ModelProvider
81  {
82  public:
83  ModelProviderRO(const RepositoryPtr& repository, const OdAnsiString& modelName = REPOSITORY_DEFAULE_MODEL_NAME)
84  : ModelProvider(!repository.isNull() ? repository->getModel(modelName) : ModelPtr())
85  {}
86 
87  ModelProviderRO(const Repository* repository, const OdAnsiString& modelName = REPOSITORY_DEFAULE_MODEL_NAME)
88  : ModelProvider(repository ? repository->getModel(modelName) : ModelPtr())
89  {}
90  };
91 
93  : public ModelProvider
94  {
95  public:
96  ModelProviderRW(RepositoryPtr& repository, const OdAnsiString& modelName = REPOSITORY_DEFAULE_MODEL_NAME)
97  : ModelProvider(!repository.isNull() ? repository->getModelRW(modelName) : ModelPtr())
98  {}
99 
100  ModelProviderRW(Repository* repository, const OdAnsiString& modelName = REPOSITORY_DEFAULE_MODEL_NAME)
101  : ModelProvider(repository ? repository->getModelRW(modelName) : ModelPtr())
102  {}
103  };
104 
105  }
106 }
107 
108 #endif // _DAI_API_UTILS_H_
109 
#define ODA_ASSERT(exp)
Definition: DebugStuff.h:49
bool isNull() const
Definition: BaseObjectPtr.h:70
OdSmartPtr< TModel > model()
Definition: daiApiUtils.h:65
ModelProvider(const ModelPtr &model)
Definition: daiApiUtils.h:47
ModelProviderRO(const Repository *repository, const OdAnsiString &modelName=REPOSITORY_DEFAULE_MODEL_NAME)
Definition: daiApiUtils.h:87
ModelProviderRO(const RepositoryPtr &repository, const OdAnsiString &modelName=REPOSITORY_DEFAULE_MODEL_NAME)
Definition: daiApiUtils.h:83
ModelProviderRW(RepositoryPtr &repository, const OdAnsiString &modelName=REPOSITORY_DEFAULE_MODEL_NAME)
Definition: daiApiUtils.h:96
ModelProviderRW(Repository *repository, const OdAnsiString &modelName=REPOSITORY_DEFAULE_MODEL_NAME)
Definition: daiApiUtils.h:100
#define REPOSITORY_DEFAULE_MODEL_NAME
Definition: daiRepository.h:37
std::shared_ptr< T > cast(CFxBIMObjectPtr pBase)
Definition: FxBIM.h:167
@ Access_type_unset
Definition: sdai.h:298