diff options
Diffstat (limited to 'src/profile.cpp')
-rw-r--r-- | src/profile.cpp | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/src/profile.cpp b/src/profile.cpp new file mode 100644 index 0000000..878a6e9 --- /dev/null +++ b/src/profile.cpp | |||
@@ -0,0 +1,116 @@ | |||
1 | #include "profile.h" | ||
2 | #include "ast.h" | ||
3 | #include "astbranch.h" | ||
4 | #include "astleaf.h" | ||
5 | #include "condition.h" | ||
6 | |||
7 | #include "conditionfiletime.h" | ||
8 | #include "conditionalways.h" | ||
9 | #include "conditionnever.h" | ||
10 | |||
11 | #include <bu/sio.h> | ||
12 | using namespace Bu; | ||
13 | |||
14 | Profile::Profile( const class AstBranch *pRoot ) : | ||
15 | pRoot( pRoot ), | ||
16 | pCond( NULL ), | ||
17 | pAst( NULL ) | ||
18 | { | ||
19 | sName = dynamic_cast<const AstLeaf *>( | ||
20 | (*pRoot->getBranchBegin()).first() | ||
21 | )->getStrValue(); | ||
22 | |||
23 | setCondition(); | ||
24 | } | ||
25 | |||
26 | Profile::Profile( const Profile &rSrc ) : | ||
27 | sName( rSrc.sName ), | ||
28 | pRoot( rSrc.pRoot ), | ||
29 | pCond( rSrc.pCond->clone() ), | ||
30 | pAst( NULL ) | ||
31 | { | ||
32 | } | ||
33 | |||
34 | Profile::~Profile() | ||
35 | { | ||
36 | delete pAst; | ||
37 | pAst = NULL; | ||
38 | } | ||
39 | |||
40 | const Bu::FString &Profile::getName() const | ||
41 | { | ||
42 | return sName; | ||
43 | } | ||
44 | |||
45 | const AstBranch *Profile::getRoot() const | ||
46 | { | ||
47 | return pRoot; | ||
48 | } | ||
49 | |||
50 | const Condition *Profile::getCond() const | ||
51 | { | ||
52 | return pCond; | ||
53 | } | ||
54 | |||
55 | bool Profile::shouldExec( class Runner &r, class Target &rTarget ) const | ||
56 | { | ||
57 | return pCond->shouldExec( r, rTarget ); | ||
58 | } | ||
59 | |||
60 | Profile *Profile::genDefaultClean() | ||
61 | { | ||
62 | Ast *pAst = new Ast(); | ||
63 | pAst->addNode( AstNode::typeProfile ); | ||
64 | pAst->openBranch(); | ||
65 | pAst->addNode( AstNode::typeString, "clean" ); | ||
66 | pAst->openBranch(); | ||
67 | pAst->addNode( AstNode::typeCondition, "always" ); | ||
68 | pAst->addNode( AstNode::typeFunction ); | ||
69 | pAst->openBranch(); | ||
70 | pAst->addNode( AstNode::typeString, "unlink" ); | ||
71 | pAst->openBranch(); | ||
72 | pAst->addNode( AstNode::typeVariable, "OUTPUT" ); | ||
73 | pAst->closeNode(); | ||
74 | pAst->closeNode(); | ||
75 | //pAst->closeNode(); | ||
76 | Profile *pRet = new Profile( | ||
77 | dynamic_cast<const AstBranch *>(*pAst->getNodeBegin()) | ||
78 | ); | ||
79 | pRet->pAst = pAst; | ||
80 | |||
81 | return pRet; | ||
82 | } | ||
83 | |||
84 | void Profile::setCondition() | ||
85 | { | ||
86 | for( AstBranch::NodeList::const_iterator i = | ||
87 | (*(pRoot->getBranchBegin()+1)).begin(); i; i++ ) | ||
88 | { | ||
89 | if( (*i)->getType() == AstNode::typeCondition ) | ||
90 | { | ||
91 | Bu::FString sCond = dynamic_cast<const AstLeaf *>(*i)->getStrValue(); | ||
92 | if( sCond == "filetime" ) | ||
93 | { | ||
94 | delete pCond; | ||
95 | pCond = new ConditionFileTime(); | ||
96 | } | ||
97 | else if( sCond == "always" ) | ||
98 | { | ||
99 | delete pCond; | ||
100 | pCond = new ConditionAlways(); | ||
101 | } | ||
102 | else if( sCond == "never" ) | ||
103 | { | ||
104 | delete pCond; | ||
105 | pCond = new ConditionNever(); | ||
106 | } | ||
107 | } | ||
108 | } | ||
109 | |||
110 | if( pCond == NULL ) | ||
111 | { | ||
112 | // The default condition | ||
113 | pCond = new ConditionFileTime(); | ||
114 | } | ||
115 | } | ||
116 | |||