blob: fd21097d4bee335f833d37908a36081158436fa3 (
plain)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
#include "profile.h"
#include "ast.h"
#include "astbranch.h"
#include "astleaf.h"
#include "condition.h"
#include "conditionplugger.h"
#include <bu/sio.h>
using namespace Bu;
Profile::Profile( const class AstBranch *pRoot ) :
pRoot( pRoot ),
pCond( NULL ),
pAst( NULL )
{
sName = dynamic_cast<const AstLeaf *>(
(*pRoot->getBranchBegin()).first()
)->getStrValue();
setCondition();
}
Profile::Profile( const Profile &rSrc ) :
sName( rSrc.sName ),
pRoot( rSrc.pRoot ),
pCond( rSrc.pCond->clone() ),
pAst( NULL )
{
}
Profile::~Profile()
{
delete pAst;
pAst = NULL;
}
const Bu::FString &Profile::getName() const
{
return sName;
}
const AstBranch *Profile::getRoot() const
{
return pRoot;
}
const Condition *Profile::getCond() const
{
return pCond;
}
bool Profile::shouldExec( class Runner &r, class Target &rTarget ) const
{
return pCond->shouldExec( r, rTarget );
}
Profile *Profile::genDefaultClean()
{
Ast *pAst = new Ast();
pAst->addNode( AstNode::typeProfile );
pAst->openBranch();
pAst->addNode( AstNode::typeString, "clean" );
pAst->openBranch();
pAst->addNode( AstNode::typeCondition, "fileExists" );
pAst->addNode( AstNode::typeFunction );
pAst->openBranch();
pAst->addNode( AstNode::typeString, "unlink" );
pAst->openBranch();
pAst->addNode( AstNode::typeVariable, "OUTPUT" );
pAst->closeNode();
pAst->closeNode();
//pAst->closeNode();
Profile *pRet = new Profile(
dynamic_cast<const AstBranch *>(*pAst->getNodeBegin())
);
pRet->pAst = pAst;
return pRet;
}
void Profile::setCondition()
{
for( AstBranch::NodeList::const_iterator i =
(*(pRoot->getBranchBegin()+1)).begin(); i; i++ )
{
if( (*i)->getType() == AstNode::typeCondition )
{
Bu::FString sCond = dynamic_cast<const AstLeaf *>(*i)->getStrValue();
delete pCond;
pCond = ConditionPlugger::getInstance().instantiate( sCond );
}
}
if( pCond == NULL )
{
// The default condition
pCond = ConditionPlugger::getInstance().instantiate("fileTime");
}
}
|