DgnLinkTree.h
Go to the documentation of this file.
1 /*--------------------------------------------------------------------------------------+
2 |
3 | Supplied under applicable software license agreement.
4 |
5 | Copyright (c) 2018 Bentley Systems, Incorporated. All rights reserved.
6 |
7 +---------------------------------------------------------------------------------------*/
8 #pragma once
9 
10 #include <ECObjects/ECObjectsAPI.h>
12 #include <Bentley/WString.h>
13 
14 DGNPLATFORM_TYPEDEFS(DgnLinkTreeSpec);
15 DGNPLATFORM_TYPEDEFS(DgnLinkTreeNode);
16 DGNPLATFORM_TYPEDEFS(DgnLinkTreeLeaf);
17 DGNPLATFORM_TYPEDEFS(DgnLinkTreeBranch);
18 DGNPLATFORM_TYPEDEFS(DgnLinkTree);
19 DGNPLATFORM_TYPEDEFS(DgnLinkUserData);
20 DGNPLATFORM_TYPEDEFS(DgnLinkSetHandler);
21 DGNPLATFORM_TYPEDEFS(DgnLinkSet);
22 DGNPLATFORM_TYPEDEFS(DgnLinkHandler);
23 DGNPLATFORM_TYPEDEFS(DgnLink);
24 DGNPLATFORM_TYPEDEFS(DgnLinkSet);
25 DGNPLATFORM_TYPEDEFS(DgnLinkValidationCenter);
26 DGNPLATFORM_TYPEDEFS(DgnLinkBookmarkProvider);
27 DGNPLATFORM_TYPEDEFS(DgnLinkUserDataList);
28 
30 
35 
36 typedef bvector<DgnLinkTreeNodeP> DgnLinkTreeNodeList;
37 
38 /*---------------------------------------------------------------------------------**/
44  {
45 protected:
47 public:
48  virtual void Release() = 0;
49  };
50 
51 /*---------------------------------------------------------------------------------**/
83 template<typename T> struct TempObjectOwner : ITempObjectOwner
84  {
85 private:
86  T* m_pointee;
87 
88  void swap (TempObjectOwner&&);
91 protected:
92  virtual void Release() override { release(); }
93 public:
95  explicit TempObjectOwner (T* pointee) : m_pointee (nullptr)
96  {
97  BeAssert (nullptr == pointee || !pointee->HasTempOwner());
98  if (nullptr != pointee && !pointee->HasTempOwner())
99  {
100  m_pointee = pointee;
101  m_pointee->SetTempOwner (this);
102  }
103  }
104 
106  TempObjectOwner() : m_pointee (nullptr)
107  {
108  //
109  }
110 
113  TempObjectOwner (TempObjectOwner&& source) : m_pointee (source.release())
114  {
115  if (nullptr != m_pointee)
116  m_pointee->SetTempOwner (this);
117  }
118 
121  {
122  reset();
123  }
124 
128  {
129  reset (source.release());
130  return *this;
131  }
132 
134  T& operator*() const
135  {
136  BeAssert (nullptr != get());
137  return *get();
138  }
139 
141  T* operator->() const
142  {
143  BeAssert (nullptr != get());
144  return get();
145  }
146 
148  T* get() const
149  {
150  return m_pointee;
151  }
152 
154  T* release()
155  {
156  T* pointee = get();
157  m_pointee = nullptr;
158  if (nullptr != pointee)
159  pointee->SetTempOwner (nullptr);
160 
161  return pointee;
162  }
163 
166  void reset (T* pointee = nullptr)
167  {
168  if (get() != pointee)
169  {
170  if (nullptr != m_pointee)
171  m_pointee->ReleaseTempOwner (this);
172 
173  m_pointee = pointee;
174  if (nullptr != m_pointee)
175  m_pointee->SetTempOwner (this);
176  }
177  }
178 
180  bool IsNull() const
181  {
182  return nullptr == get();
183  }
184 
186  bool IsValid() const
187  {
188  return !IsNull();
189  }
190  };
191 
198 
199 
201  {
202  Success = 0,
203  GeneralError,
205  };
206 
207 //struct DgnFileAdapter;
208 struct DgnLinkHolder;
209 /*=================================================================================**/
217  {
218 
220  typedef bvector<DgnLinkUserDataPtr> DgnLinkUserDataVector;
221 
223  typedef DgnLinkUserDataVector::const_iterator const_iterator;
224 
225 private:
226  const bvector<DgnLinkUserDataPtr> &m_userDataVector;
227 
229 
230 public:
233 
236 
239  };
240 
241 /*=================================================================================**/
251  {
252 protected:
254  DGNPLATFORM_EXPORT bool HasTempOwner() const;
255  DGNPLATFORM_EXPORT void SetTempOwner (ITempObjectOwner* owner);
256  DGNPLATFORM_EXPORT void ReleaseTempOwner (ITempObjectOwner* owner);
257 private:
258  virtual void MakeClassAbstract() = 0;
259 public:
260 public:
262  DGNPLATFORM_EXPORT TempDgnLinkTreeNodeOwner Copy (DgnLinkTreeSpecCR) const;
263 
265  DGNPLATFORM_EXPORT StatusInt SetName (WCharCP name, bool checkForDuplicateNames = true);
266 
268  DGNPLATFORM_EXPORT WCharCP GetName () const;
269 
271  DGNPLATFORM_EXPORT WString GetPathName () const;
272 
275  DGNPLATFORM_EXPORT WString GetHybridPathName () const;
276 
278  DGNPLATFORM_EXPORT WString GetHandlerKey () const;
279 
281  DGNPLATFORM_EXPORT DgnLinkTreeCP GetTreeCP () const;
282 
284  DGNPLATFORM_EXPORT DgnLinkTreeP GetTreeP ();
285 
287  DGNPLATFORM_EXPORT DgnLinkTreeBranchCP GetParentCP () const;
288 
290  DGNPLATFORM_EXPORT DgnLinkTreeBranchP GetParentP ();
291 
293  DGNPLATFORM_EXPORT bool IsDirty () const;
294 
296  DGNPLATFORM_EXPORT void SetDirtyFlag ();
297 
299  DGNPLATFORM_EXPORT void ClearDirtyFlag ();
300 
302  DGNPLATFORM_EXPORT size_t GetUserDataCount (UInt32 *pAppID, UInt32 *pSubID) const;
303 
305  DGNPLATFORM_EXPORT DgnLinkUserDataCP GetUserData (UInt32 *pAppID, UInt32 *pSubID, UInt32 index) const;
306 
308  DGNPLATFORM_EXPORT StatusInt AddUserData (DgnLinkUserDataR);
309 
311  DGNPLATFORM_EXPORT StatusInt RemoveUserData (DgnLinkUserDataCR value);
312 
314  DGNPLATFORM_EXPORT DgnLinkUserDataList GetUserDataList () const;
315 
317  DGNPLATFORM_EXPORT UInt32 GetNodeId() const;
318 
321  DGNPLATFORM_EXPORT DgnLinkTreeBranchCP AsDgnLinkTreeBranchCP() const;
322 
325  DGNPLATFORM_EXPORT DgnLinkTreeBranchP AsDgnLinkTreeBranchP();
326 
329  DGNPLATFORM_EXPORT DgnLinkTreeLeafCP AsDgnLinkTreeLeafCP() const;
330 
333  DGNPLATFORM_EXPORT DgnLinkTreeLeafP AsDgnLinkTreeLeafP();
334  }; // DgnLinkTreeNode
335 
336 /*=================================================================================**/
345  {
348 private:
349  virtual void MakeClassAbstract() = 0;
350 public:
351 
352 public:
354  DGNPLATFORM_EXPORT DgnLinkSetHandlerP GetHandler () const;
356  DGNPLATFORM_EXPORT DgnLinkSetCP GetLinkSetCP () const;
358  DGNPLATFORM_EXPORT DgnLinkSetP GetLinkSetP();
360  DGNPLATFORM_EXPORT size_t GetChildCount () const;
362  DGNPLATFORM_EXPORT DgnLinkTreeNodeP GetChildP (size_t iChild);
364  DGNPLATFORM_EXPORT DgnLinkTreeNodeCP GetChildCP(size_t iChild) const;
366  DGNPLATFORM_EXPORT DgnLinkTreeNodeCP FindChildNode (WCharCP path, bool searchProxyTrees) const;
368  DGNPLATFORM_EXPORT DgnLinkTreeNodeP FindChildNode(WCharCP path, bool searchProxyTrees);
370  DGNPLATFORM_EXPORT StatusInt FindChildIndex (WCharCP name, size_t &index) const;
372  DGNPLATFORM_EXPORT size_t FindChildIndex(DgnLinkTreeNodeCR childP) const;
374  DGNPLATFORM_EXPORT DgnLinkAddChildStatus AddChild (DgnLinkTreeNodeR newNode, size_t index);
376  DGNPLATFORM_EXPORT StatusInt DropChild (size_t iChild);
378  DGNPLATFORM_EXPORT WString GetUniqueChildName (WCharCP namePrefix) const;
380  DGNPLATFORM_EXPORT TempDgnLinkTreeBranchOwner DeepCopy (DgnLinkTreeSpecCR) const;
381  }; // DgnLinkTreeBranch
382 
383 /*=================================================================================**/
390  {
393 private:
394  virtual void MakeClassAbstract() = 0;
395 public:
396 protected:
398  virtual ~DgnLinkTreeLeaf ();
399 public:
401  DGNPLATFORM_EXPORT DgnLinkHandlerP GetHandler () const;
403  DGNPLATFORM_EXPORT DgnLinkCP GetLinkCP () const;
405  DGNPLATFORM_EXPORT DgnLinkP GetLinkP();
407  DGNPLATFORM_EXPORT bool GetValidFlag () const;
409  DGNPLATFORM_EXPORT void SetValidFlag(bool val);
411  DGNPLATFORM_EXPORT size_t GetSequenceNumber ();
412 
413  }; // DgnLinkTreeLeaf
414 
416 enum class DgnLinkTreeKey
417  {
418  Invalid = 0,
419  Project = 1,
420  Bookmarks = 2,
421  Annotation = 3,
422  SheetIndex = 4,
423  };
424 
425 /*=================================================================================**/
434  {
435 
436 public:
438  DGNPLATFORM_EXPORT DgnLinkTreeKey GetTypeKey () const;
440  DGNPLATFORM_EXPORT WCharCP GetTreeName () const;
442  DGNPLATFORM_EXPORT WString GetFilePath() const;
444  DGNPLATFORM_EXPORT DgnDocumentMonikerCR GetDocumentMoniker() const;
446  DGNPLATFORM_EXPORT DgnDocumentMonikerPtr GetDocumentMonikerPtr() const;
448  DGNPLATFORM_EXPORT WCharCP GetModelName() const;
450  DGNPLATFORM_EXPORT ElementId GetElementId() const;
452  DGNPLATFORM_EXPORT int Compare (DgnLinkTreeSpecCR otherSpec) const;
453  };
454 
455 /*=================================================================================**/
465  {
466 private:
467  virtual void MakeClassAbstract() = 0;
468 public:
469 public:
471  DGNPLATFORM_EXPORT WString GetName () const;
473  DGNPLATFORM_EXPORT DgnLinkTreeSpecCR GetTreeSpec () const;
475  DGNPLATFORM_EXPORT DgnLinkTreeSpecPtr GetTreeSpecPtr() const;
477  DGNPLATFORM_EXPORT WString GetFilePath () const;
479  DGNPLATFORM_EXPORT void TransformTo(DgnDocumentMonikerCR dest);
481  DGNPLATFORM_EXPORT DgnLinkTreeBranchCR GetRoot () const;
483  DGNPLATFORM_EXPORT DgnLinkTreeBranchR GetRootR();
485  DGNPLATFORM_EXPORT void SetRoot(DgnLinkTreeBranchR root);
487  DGNPLATFORM_EXPORT DgnLinkTreeNodeCP FindNode (WCharCP path, bool searchBookmarkTree) const;
489  DGNPLATFORM_EXPORT DgnLinkTreeNodeP FindNode(WCharCP path, bool searchBookmarkTree);
491  DGNPLATFORM_EXPORT DgnLinkTreeLeafCP GetBookmarkProviderNode () const;
493  DGNPLATFORM_EXPORT void SetBookmarkProviderNode(DgnLinkTreeLeafCR providerNode);
495  DGNPLATFORM_EXPORT UInt32 GetTreeId () const;
497  DGNPLATFORM_EXPORT DgnLinkTreeNodeCP FindNodeById (UInt32 nodeId) const;
499  DGNPLATFORM_EXPORT DgnLinkTreeNodeP FindNodeById (UInt32 nodeId);
501  DGNPLATFORM_EXPORT UInt64 GetLastModifiedTime () const;
503  DGNPLATFORM_EXPORT static DgnLinkTreePtr Create (DgnLinkTreeBranchP root, DgnDocumentMonikerP ownerMoniker, DgnLinkTreeLeafCP provider);
504  }; // DgnLinkTree
505 
507 
DgnLinkUserDataVector::const_iterator const_iterator
const iterator for DgnLinkUserDataVector
Definition: DgnLinkTree.h:223
struct DgnPlatform::DgnDocumentMoniker const & DgnDocumentMonikerCR
Definition: DgnPlatform.h:197
bvector< DgnLinkUserDataPtr > DgnLinkUserDataVector
Vector of DgnLinkUserData.
Definition: DgnLinkTree.h:220
#define END_BENTLEY_DGNPLATFORM_NAMESPACE
Definition: DgnPlatformBaseType.r.h:69
DgnLinkTreeLeaf represents leaf nodes in the DgnLinkTree.
Definition: DgnLinkTree.h:389
DGNPLATFORM_TYPEDEFS(DgnLinkTreeSpec)
iterator begin()
Definition: stdcxx/bstdmap.h:178
bool IsNull() const
Returns true if the pointee is null.
Definition: DgnLinkTree.h:180
iterator end()
Definition: stdcxx/bstdmap.h:186
DgnLinkTree represents a tree structure to hold DgnLinks.
Definition: DgnLinkTree.h:464
void swap(basic_string< _CharT, _Traits, _Allocator > &__a, basic_string< _CharT, _Traits, _Allocator > &__b)
Definition: basic_string.h:1396
DgnLinkAddChildStatus
Definition: DgnLinkTree.h:200
#define DGNPLATFORM_EXPORT
Definition: DgnPlatform/ExportMacros.h:58
wchar_t const * WCharCP
Definition: Bentley.h:224
RefCountedPtr< DgnLinkUserData > DgnLinkUserDataPtr
Definition: DgnLinkTree.h:33
uint32_t UInt32
Definition: Bentley.r.h:128
TempObjectOwner< DgnLinkTreeLeaf > TempDgnLinkTreeLeafOwner
A smart pointer to a DgnLinkTreeLeaf which ensures the pointee is freed if ownership is not transferr...
Definition: DgnLinkTree.h:195
bstdmap & operator=(const bstdmap &__rhs)
Definition: stdcxx/bstdmap.h:170
~TempObjectOwner()
Destructor. Releases the pointee if its ownership has not been assumed by another object...
Definition: DgnLinkTree.h:120
T * release()
Releases ownership of the pointee and returns it. Does NOT free the pointee. Caller is responsible fo...
Definition: DgnLinkTree.h:154
RefCountedPtr< DgnLinkTreeSpec > DgnLinkTreeSpecPtr
Definition: DgnLinkTree.h:31
A DgnDocumentMoniker identifies a file.
Definition: DgnDocumentManager.h:181
TempObjectOwner & operator=(TempObjectOwner &&source)
Transfers ownership of the pointee from the source to this.
Definition: DgnLinkTree.h:127
RefCountedPtr< DgnLinkSet > DgnLinkSetPtr
Definition: DgnLinkTree.h:34
A shared pointer template for reference-counted objects.
Definition: RefCounted.h:119
struct DgnPlatform::DgnLink const * DgnLinkCP
Definition: DgnLinks.h:21
ITempObjectOwner()
Definition: DgnLinkTree.h:46
DgnLinkTreeBranch is a type of DgnLinkTreeNode.
Definition: DgnLinkTree.h:344
Every node in DgnLinkTree is represented by DgnLinkTreeNode.
Definition: DgnLinkTree.h:250
virtual void Release() override
Definition: DgnLinkTree.h:92
uint64_t UInt64
Definition: Bentley.r.h:131
TempObjectOwner(T *pointee)
Constructs a TempObjectOwner to the specified pointee. If another TempObjectOwner already points to p...
Definition: DgnLinkTree.h:95
#define BEGIN_BENTLEY_DGNPLATFORM_NAMESPACE
Definition: DgnPlatformBaseType.r.h:68
A smart pointer to an object of type T, where the pointee is an object which under ordinary circumsta...
Definition: DgnLinkTree.h:83
int StatusInt
Definition: Bentley.h:222
Concrete class that can be used to implement the reference-counting pattern.
Definition: RefCounted.h:109
UInt64 ElementId
Definition: DgnPlatformBaseType.r.h:83
TempObjectOwner()
Constructs an empty TempObjectOwner (with a null pointee).
Definition: DgnLinkTree.h:106
DgnLinkTreeSpec contains the information necessary to locate a DgnLinkTree in the DgnFile...
Definition: DgnLinkTree.h:433
TempObjectOwner(TempObjectOwner &&source)
Move-constructor.
Definition: DgnLinkTree.h:113
TempObjectOwner< DgnLinkTreeNode > TempDgnLinkTreeNodeOwner
A smart pointer to a DgnLinkTreeNode which ensures the pointee is freed if ownership is not transferr...
Definition: DgnLinkTree.h:193
#define BeAssert(_Expression)
BeAssert performs the same function as the standard assert, plus it prevents the most common cases of...
Definition: BeAssert.h:56
TempObjectOwner< DgnLinkTreeBranch > TempDgnLinkTreeBranchOwner
A smart pointer to a DgnLinkTreeBranch which ensures the pointee is freed if ownership is not transfe...
Definition: DgnLinkTree.h:197
DgnLinkTreeKey
The DgnLinkTreeKey defines the location at which a link tree can be stored.
Definition: DgnLinkTree.h:416
void reset(T *pointee=nullptr)
Changes the pointee.
Definition: DgnLinkTree.h:166
Interface adopted by an object which can assume temporary ownership of an object whose lifetime is or...
Definition: DgnLinkTree.h:43
bool IsValid() const
Returns true if the pointee is non-null.
Definition: DgnLinkTree.h:186
Applications can store their user data on DgnLinkTreeNode.
Definition: DgnLinkTree.h:216
RefCountedPtr< DgnLinkTree > DgnLinkTreePtr
Definition: DgnLinkTree.h:32
T * operator->() const
Dereferences the pointee. Invalid if pointee is null.
Definition: DgnLinkTree.h:141
A string class that has many of the same capabilities as std::string, plus additional functions such ...
Definition: WString.h:51
T & operator*() const
Returns a reference to the pointee. Invalid if pointee is null.
Definition: DgnLinkTree.h:134
bvector< DgnLinkTreeNodeP > DgnLinkTreeNodeList
Definition: DgnLinkTree.h:36

Copyright © 2017 Bentley Systems, Incorporated. All rights reserved.