summaryrefslogtreecommitdiff
path: root/datamodel/dependencygraph.h
blob: 1383c4ad820f8e23ba798c4d7d1b955045344bdc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
//=============================================================================

#ifndef DEPENDENCYGRAPH_H
#define DEPENDENCYGRAPH_H
#ifdef _WIN32
#pragma once
#endif

#include "tier1/utlvector.h"
#include "tier1/utlhash.h"

//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
class CDmAttribute;
class IDmeOperator;
struct COperatorNode;
class CAttributeNode;


//-----------------------------------------------------------------------------
// CDependencyGraph class - sorts operators based upon the input/output graph
//-----------------------------------------------------------------------------
class CDependencyGraph
{
public:
	CDependencyGraph();
	~CDependencyGraph();

	void Reset( const CUtlVector< IDmeOperator * > &operators );

	// caches only the operators that need to be evaluated, sorted by dependencies
	// returns true if a cycle found - in this case, an arbitrary link of the cycle will be ignored
	bool CullAndSortOperators();

	const CUtlVector< IDmeOperator* > &GetSortedOperators() const { return m_operators; }

private:
	static bool GetOperatorOrdering( CUtlVector< COperatorNode* > &pOpNodes, CUtlVector< IDmeOperator * > &operators );
	static void DBG_PrintOperator( const char *pIndent, IDmeOperator *pOp );

	friend class CDmElementFramework;

	void Cleanup();
	void FindRoots();
	CAttributeNode *FindAttrNode( CDmAttribute *pAttr );

	CUtlVector< COperatorNode* > m_opRoots;
//	CUtlVector< COperatorNode* > m_opLeaves;

	CUtlVector< COperatorNode* > m_opNodes;

	CUtlHash< CAttributeNode* > m_attrNodes;

	CUtlVector< IDmeOperator* > m_operators;
};

#endif // DEPENDENCYGRAPH_H