CFx SDK Documentation 2026 SP0
Loading...
Searching...
No Matches
DbGraph.h
Go to the documentation of this file.
1
2// Copyright (C) 2002-2024, 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 Open Design Alliance software pursuant to a license
16// agreement with Open Design Alliance.
17// Open Design Alliance Copyright (C) 2002-2024 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
25
26
27#ifndef _ODDBGRAPH_H_INCLUDED_
28#define _ODDBGRAPH_H_INCLUDED_
29
30#include "TD_PackPush.h"
31
32#include "OdaDefs.h"
33#include "DbExport.h"
34#include "RxObject.h"
35#include "OdArray.h"
36
37class OdDbGraph;
38class OdDbGraphNode;
39
44
71class TOOLKIT_EXPORT OdDbGraphNode : public OdRxObject
72{
73 friend class OdDbGraph;
74public:
75 OdDbGraphNode() : m_pData(0), m_flags(0), m_pOwner(0) {}
76
78
79 virtual ~OdDbGraphNode();
80
81 enum Flags
82 {
83 kNone = 0x00, // None.
84 kVisited = 0x01, // Used internally by OdDbGraph::findCycles() and while traversing a graphs with cycles.
85 kOutsideRefed = 0x02, // Used internally by Xref detach.
86 kSelected = 0x04, // User selection. Set by getOutgoing.
87 kInList = 0x08, // Is *in* list. Set by getOutgoing.
88 kListAll = 0x0E, // Used to *clear* kSelected, kInList, and kOutsideRefed.
89 kFirstLevel = 0x10, // The *node* is connected to the root *node*. Read Only.
90 kUnresTree = 0x20, // The tree is unresolved.
91 kAll = 0x2F // Used to *clear* all but kFirstLevel.
92 };
93
97 void* data() const { return m_pData; }
98
105 void* pData) { m_pData = pData; }
106
110 int numOut() const { return m_outgoing.size(); }
111
115 int numIn() const { return m_incoming.size(); }
116
126 int refIndex) const { return m_incoming.at(refIndex); }
127
136 int refIndex) const { return m_outgoing.at(refIndex); }
137
154 OdDbGraphNode* pTo);
155
167 OdDbGraphNode* pNode);
168
176
180 OdDbGraph* owner() const { return m_pOwner; }
181
204 OdUInt8 flags) const { return ((m_flags & flags)==flags); }
205
227 void markAs(
228 OdUInt8 flags)
229 {
230 if(!GETBIT(flags, kFirstLevel))
231 {
232 m_flags |= flags;
233 }
234 else
235 {
236 throw OdError(eInvalidInput);
237 }
238 }
239
261 void clear(
262 OdUInt8 flags)
263 {
264 if(!GETBIT(flags, kFirstLevel))
265 {
266 m_flags &= (~flags);
267 }
268 else
269 {
270 throw OdError(eInvalidInput);
271 }
272 }
273
274
305 OdUInt8 flags,
306 OdDbGraphNodeArray* pNodeArray = 0);
307
308 // Circularity detection methods
309
317 int numCycleOut() const { return m_cycleOut.size(); }
318
326 int numCycleIn() const { return m_cycleIn.size(); }
327
341 int refIndex) const { return m_cycleIn[refIndex]; }
342
356 int refIndex) const { return m_cycleOut[refIndex]; }
357
368 OdDbGraphNode* nextCycleNode() const { return cycleOut(0); }
369
377 bool isCycleNode() const { return (numCycleOut() != 0 || numCycleIn() != 0); }
378
379private:
380 void setOwner(
381 OdDbGraph* pGraph)
382 {
383 if(m_pOwner)
384 {
385 ODA_FAIL();
386 throw OdError(eInvalidOwnerObject);
387 }
388 m_pOwner = pGraph;
389 }
390
391 friend struct if_leaf_push_to;
392 friend struct clear_cycles;
394
395 void* m_pData;
396 OdUInt8 m_flags;
397 OdDbGraphNodeArray m_outgoing;
398 OdDbGraphNodeArray m_incoming;
399 OdDbGraph* m_pOwner;
400 OdDbGraphNodeArray m_cycleOut;
401 OdDbGraphNodeArray m_cycleIn;
402};
403
407
415{
416public:
427 int initPhysicalLength = 0,
428 int initGrowLength = 8)
429 : m_stack(initPhysicalLength, initGrowLength) {}
430
432
438 void push(
439 OdDbGraphNode* pNode) { m_stack.push_back(pNode); }
440
448 {
449 if(!isEmpty())
450 {
451 OdDbGraphNode* pRes = top();
452 m_stack.removeLast();
453 return pRes;
454 }
455 return 0;
456 }
457
458
465 OdDbGraphNode* top() const { return isEmpty() ? 0 : m_stack.last(); }
466
470 bool isEmpty() const { return m_stack.empty(); }
471private:
472 OdDbGraphNodeArray m_stack;
473};
474
500{
501 friend class OdDbGraphNode;
502public:
503 OdDbGraph() : m_bDirty(false), m_nNonCycleNodes(0) {}
504 virtual ~OdDbGraph();
505
512 int nodeIndex) const { return m_nodes.at(nodeIndex); }
513
521
527 int numNodes() const { return m_nodes.size(); }
528
532 bool isEmpty() const { return numNodes() == 0; }
533
544 OdDbGraphNode* pNode);
545
559 OdDbGraphNode* pFrom,
560 OdDbGraphNode* pTo);
561
568 OdDbGraphNode* pNode);
569
576 void reset();
577
602 OdUInt8 flags);
603
612 OdDbGraphNodeArray& outgoing);
613
624 virtual bool findCycles(
625 OdDbGraphNode* pStart = 0);
633 OdDbGraphNode* pFrom,
634 OdDbGraphNode* pTo);
635
636protected:
648private:
649 OdDbGraph(
650 const OdDbGraph&);
651 OdDbGraph& operator =(
652 const OdDbGraph&);
653
654 void removeLeaves(
655 OdDbGraphStack& stack);
656 void setDirty() { m_bDirty = true; }
657 bool isDirty() const { return m_bDirty; }
658 bool m_bDirty;
659 OdDbGraphNodeArray::size_type m_nNonCycleNodes;
660 OdDbGraphNodeArray m_nodes;
661};
662
663#include "TD_PackPop.h"
664
665#endif // _ODDBGRAPH_H_INCLUDED_
#define TOOLKIT_EXPORT
Definition DbExport.h:40
OdSmartPtr< OdDbGraphNode > OdDbGraphNodePtr
Definition DbGraph.h:406
OdArray< OdDbGraphNode *, OdMemoryAllocator< OdDbGraphNode * > > OdDbGraphNodeArray
Definition DbGraph.h:43
#define ODA_FAIL()
Definition DebugStuff.h:88
false
Definition DimVarDefs.h:165
unsigned char OdUInt8
#define GETBIT(flags, bit)
Definition OdaDefs.h:517
typename OdMemoryAllocator< OdDbGraphNode * >::size_type size_type
Definition OdArray.h:837
void getOutgoing(OdDbGraphNodeArray &outgoing)
OdDbGraph()
Definition DbGraph.h:503
void clearAllCycles()
void clearAll(OdUInt8 flags)
OdDbGraphNode * node(int nodeIndex) const
Definition DbGraph.h:511
friend class OdDbGraphNode
Definition DbGraph.h:501
void addNode(OdDbGraphNode *pNode)
void delNode(OdDbGraphNode *pNode)
void breakCycleEdge(OdDbGraphNode *pFrom, OdDbGraphNode *pTo)
void addEdge(OdDbGraphNode *pFrom, OdDbGraphNode *pTo)
virtual bool findCycles(OdDbGraphNode *pStart=0)
int numNodes() const
Definition DbGraph.h:527
void reset()
OdDbGraphNode * rootNode() const
bool isEmpty() const
Definition DbGraph.h:532
virtual ~OdDbGraph()
OdDbGraph * owner() const
Definition DbGraph.h:180
friend struct if_leaf_push_to
Definition DbGraph.h:391
friend class OdDbGraph
Definition DbGraph.h:73
bool isMarkedAs(OdUInt8 flags) const
Definition DbGraph.h:203
OdDbGraphNode * cycleIn(int refIndex) const
Definition DbGraph.h:340
int numIn() const
Definition DbGraph.h:115
void addRefTo(OdDbGraphNode *pTo)
void markAs(OdUInt8 flags)
Definition DbGraph.h:227
friend struct clear_cycles
Definition DbGraph.h:392
virtual ~OdDbGraphNode()
OdDbGraphNode * nextCycleNode() const
Definition DbGraph.h:368
void clear(OdUInt8 flags)
Definition DbGraph.h:261
void * data() const
Definition DbGraph.h:97
void setData(void *pData)
Definition DbGraph.h:104
int numCycleOut() const
Definition DbGraph.h:317
bool isCycleNode() const
Definition DbGraph.h:377
OdDbGraphNode * cycleOut(int refIndex) const
Definition DbGraph.h:355
void disconnectAll()
int numCycleIn() const
Definition DbGraph.h:326
void removeRefTo(OdDbGraphNode *pNode)
OdDbGraphNode * out(int refIndex) const
Definition DbGraph.h:135
OdDbGraphNode * in(int refIndex) const
Definition DbGraph.h:125
void markTree(OdUInt8 flags, OdDbGraphNodeArray *pNodeArray=0)
int numOut() const
Definition DbGraph.h:110
ODRX_DECLARE_MEMBERS(OdDbGraphNode)
friend void break_edge(OdDbGraphNode *, OdDbGraphNode *)
OdDbGraphNode * pop()
Definition DbGraph.h:447
bool isEmpty() const
Definition DbGraph.h:470
OdDbGraphStack(int initPhysicalLength=0, int initGrowLength=8)
Definition DbGraph.h:426
OdDbGraphNode * top() const
Definition DbGraph.h:465
void push(OdDbGraphNode *pNode)
Definition DbGraph.h:438