CFx SDK Documentation  2023 SP0
GiTraitsCache.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2017, 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-2017 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 _ODGITRAITSCACHE_INCLUDED_
25 #define _ODGITRAITSCACHE_INCLUDED_
26 
27 #include "GiCommonDraw.h"
28 
29 #define STL_USING_MAP
30 #include "OdaSTL.h"
31 
32 class OdDbStub;
33 
34 #include "TD_PackPush.h"
35 
43 template <class traitsContainer, class traitsTaker, OdUInt32 byMask = 0>
44 class OdGiTraitsCache : public traitsTaker
45 {
46  public:
47  enum CacheType
48  {
51  kCacheAll = 2
52  };
53  protected:
54  struct CacheEntry
55  {
56  traitsContainer m_data;
58  void set(const traitsContainer& data, OdUInt32 flags) { m_data = data; m_flags = flags; }
59  };
60 
61  protected:
63  typedef std::map<OdDbStub*, CacheEntry> _mmap;
66  public:
68  : traitsTaker()
70  , m_traitsAttrib(0)
71  {
72  }
74  : traitsTaker()
76  , m_traitsAttrib(0)
77  {
78  }
80  {
81  }
82 
84  {
86  }
88  {
89  return m_cacheType;
90  }
91 
92  void setAttributes(OdDbStub* objId, OdGiContext &giCtx, bool forceCaching = false)
93  {
94  if (m_cacheType != kCacheNone && m_cacheData.size() > 0)
95  {
96  // Note: iterator won't compile in this context on all platforms.
97  typename _mmap::iterator it = m_cacheData.find(objId);
98  if(it != m_cacheData.end())
99  {
100  m_traitsAttrib = it->second.m_flags;
101  if(!(m_traitsAttrib & byMask))
102  traitsTaker::setData(it->second.m_data);
103  return;
104  }
105  }
106  OdGiDrawablePtr drawable = giCtx.openDrawable(objId);
107  if (!drawable.isNull())
108  {
109  m_traitsAttrib = drawable->setAttributes(this);
110  if (m_cacheType != kCacheNone)
111  {
112  if (m_cacheType == kCacheAll || forceCaching || ((m_traitsAttrib & byMask) != 0))
113  {
114  m_cacheData[objId].set(this->getData(), m_traitsAttrib);
115  }
116  }
117  }
118  }
119 
120  void setFlags(OdUInt32 uAttrib)
121  {
122  m_traitsAttrib = uAttrib;
123  }
125  {
126  return m_traitsAttrib;
127  }
128 
129  void clear()
130  {
131  m_cacheData.clear();
132  }
133 };
134 
135 // traitsContainer - must have operator =.
136 // traitsTaker - must have setData(traitsContainer), getData() methods.
137 
138 #include "TD_PackPop.h"
139 
140 #endif // #ifndef _ODGITRAITSCACHE_INCLUDED_
unsigned int OdUInt32
bool isNull() const
Definition: BaseObjectPtr.h:70
virtual OdGiDrawablePtr openDrawable(OdDbStub *drawableId)=0
ODRX_SEALED_VIRTUAL OdUInt32 setAttributes(OdGiDrawableTraits *pTraits) const ODRX_SEALED
OdUInt32 m_traitsAttrib
Definition: GiTraitsCache.h:65
OdGiTraitsCache(CacheType cacheType)
Definition: GiTraitsCache.h:73
CacheType m_cacheType
Definition: GiTraitsCache.h:62
std::map< OdDbStub *, CacheEntry > _mmap
Definition: GiTraitsCache.h:63
void setFlags(OdUInt32 uAttrib)
CacheType cacheType() const
Definition: GiTraitsCache.h:87
void setCacheType(CacheType cacheType)
Definition: GiTraitsCache.h:83
void setAttributes(OdDbStub *objId, OdGiContext &giCtx, bool forceCaching=false)
Definition: GiTraitsCache.h:92
OdUInt32 getFlags() const
GLint GLenum GLsizei GLsizei GLint GLsizei const void * data
Definition: gles2_ext.h:110
Definition: GiTraitsCache.h:55
OdUInt32 m_flags
Definition: GiTraitsCache.h:57
traitsContainer m_data
Definition: GiTraitsCache.h:56
void set(const traitsContainer &data, OdUInt32 flags)
Definition: GiTraitsCache.h:58