CFx SDK Documentation 2024 SP0
Loading...
Searching...
No Matches
DbGraph.h
Go to the documentation of this file.
1
2// Copyright (C) 2002-2022, 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-2022 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
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
307 OdUInt8 flags,
308 OdDbGraphNodeArray* pNodeArray = 0);
309
310 // Circularity detection methods
311
319 int numCycleOut() const { return m_cycleOut.size(); }
320
328 int numCycleIn() const { return m_cycleIn.size(); }
329
343 int refIndex) const { return m_cycleIn[refIndex]; }
344
358 int refIndex) const { return m_cycleOut[refIndex]; }
359
370 OdDbGraphNode* nextCycleNode() const { return cycleOut(0); }
371
379 bool isCycleNode() const { return (numCycleOut() != 0 || numCycleIn() != 0); }
380
381private:
382 void setOwner(
383 OdDbGraph* pGraph)
384 {
385 if(m_pOwner)
386 {
387 ODA_FAIL();
388 throw OdError(eInvalidOwnerObject);
389 }
390 m_pOwner = pGraph;
391 }
392
393 friend struct if_leaf_push_to;
394 friend struct clear_cycles;
396
397 void* m_pData;
398 OdUInt8 m_flags;
399 OdDbGraphNodeArray m_outgoing;
400 OdDbGraphNodeArray m_incoming;
401 OdDbGraph* m_pOwner;
402 OdDbGraphNodeArray m_cycleOut;
403 OdDbGraphNodeArray m_cycleIn;
404};
409
417{
418public:
429 int initPhysicalLength = 0,
430 int initGrowLength = 8)
431 : m_stack(initPhysicalLength, initGrowLength) {}
432
434
440 void push(
441 OdDbGraphNode* pNode) { m_stack.push_back(pNode); }
442
450 {
451 if(!isEmpty())
452 {
453 OdDbGraphNode* pRes = top();
454 m_stack.removeLast();
455 return pRes;
456 }
457 return 0;
458 }
459
460
467 OdDbGraphNode* top() const { return isEmpty() ? 0 : m_stack.last(); }
468
472 bool isEmpty() const { return m_stack.empty(); }
473private:
474 OdDbGraphNodeArray m_stack;
475};
476
502{
503 friend class OdDbGraphNode;
504public:
505 OdDbGraph() : m_bDirty(false), m_nNonCycleNodes(0) {}
506 virtual ~OdDbGraph();
507
514 int nodeIndex) const { return m_nodes.at(nodeIndex); }
515
523
529 int numNodes() const { return m_nodes.size(); }
530
534 bool isEmpty() const { return numNodes() == 0; }
535
546 OdDbGraphNode* pNode);
547
561 OdDbGraphNode* pFrom,
562 OdDbGraphNode* pTo);
563
570 OdDbGraphNode* pNode);
571
578 void reset();
579
604 OdUInt8 flags);
605
614 OdDbGraphNodeArray& outgoing);
615
626 virtual bool findCycles(
627 OdDbGraphNode* pStart = 0);
635 OdDbGraphNode* pFrom,
636 OdDbGraphNode* pTo);
637
638protected:
650private:
651 OdDbGraph(
652 const OdDbGraph&);
653 OdDbGraph& operator =(
654 const OdDbGraph&);
655
656 void removeLeaves(
657 OdDbGraphStack& stack);
658 void setDirty() { m_bDirty = true; }
659 bool isDirty() const { return m_bDirty; }
660 bool m_bDirty;
661 OdDbGraphNodeArray::size_type m_nNonCycleNodes;
662 OdDbGraphNodeArray m_nodes;
663};
664
665#include "TD_PackPop.h"
666
667#endif // _ODDBGRAPH_H_INCLUDED_
#define TOOLKIT_EXPORT
Definition: DbExport.h:40
OdSmartPtr< OdDbGraphNode > OdDbGraphNodePtr
Definition: DbGraph.h:408
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
bool empty() const
Definition: OdArray.h:1257
OdArray & removeLast()
Definition: OdArray.h:1894
void push_back(const T &value)
Definition: OdArray.h:1411
T & last()
Definition: OdArray.h:1710
void getOutgoing(OdDbGraphNodeArray &outgoing)
OdDbGraph()
Definition: DbGraph.h:505
void clearAllCycles()
void clearAll(OdUInt8 flags)
OdDbGraphNode * node(int nodeIndex) const
Definition: DbGraph.h:513
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:529
void reset()
OdDbGraphNode * rootNode() const
bool isEmpty() const
Definition: DbGraph.h:534
virtual ~OdDbGraph()
OdDbGraph * owner() const
Definition: DbGraph.h:180
bool isMarkedAs(OdUInt8 flags) const
Definition: DbGraph.h:203
OdDbGraphNode * cycleIn(int refIndex) const
Definition: DbGraph.h:342
int numIn() const
Definition: DbGraph.h:115
void addRefTo(OdDbGraphNode *pTo)
void markAs(OdUInt8 flags)
Definition: DbGraph.h:227
virtual ~OdDbGraphNode()
OdDbGraphNode * nextCycleNode() const
Definition: DbGraph.h:370
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:319
bool isCycleNode() const
Definition: DbGraph.h:379
OdDbGraphNode * cycleOut(int refIndex) const
Definition: DbGraph.h:357
void disconnectAll()
int numCycleIn() const
Definition: DbGraph.h:328
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)
OdDbGraphNode()
Definition: DbGraph.h:75
int numOut() const
Definition: DbGraph.h:110
ODRX_DECLARE_MEMBERS(OdDbGraphNode)
friend void break_edge(OdDbGraphNode *, OdDbGraphNode *)
OdDbGraphNode * pop()
Definition: DbGraph.h:449
bool isEmpty() const
Definition: DbGraph.h:472
OdDbGraphStack(int initPhysicalLength=0, int initGrowLength=8)
Definition: DbGraph.h:428
OdDbGraphNode * top() const
Definition: DbGraph.h:467
void push(OdDbGraphNode *pNode)
Definition: DbGraph.h:440