aboutsummaryrefslogtreecommitdiff
path: root/src/action.cpp
blob: 51868ebfc5fa7ca661c0bee19239908ad49910d1 (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
#include "action.h"
#include "command.h"
#include "builder.h"

Action::Action() :
	bDefault( true ),
	sName("")
{
}

Action::Action( const char *sName ) :
	bDefault( false ),
	sName( sName )
{
}

Action::~Action()
{
}

void Action::add( Command *pCmd )
{
	lCommand.push_back( pCmd );
}

void Action::add( int nType, const char *sCmd )
{
	lRegExCommand.push_back( std::pair<int,std::string>( nType, sCmd ) );
}

void Action::debug()
{
	if( bDefault )
		printf("   action default:\n");
	else
		printf("   action \"%s\":\n", sName.getString() );

	for( std::list<Command *>::iterator i = lCommand.begin();
		 i != lCommand.end(); i++ )
	{
		(*i)->debug();
	}
}

void Action::execute( Builder &bld )
{
	for( std::list<std::pair<int,std::string> >::iterator i =
		 lRegExCommand.begin(); i != lRegExCommand.end(); i++ )
	{
		std::list<std::string> lTmp = bld.findTargets( (*i).second.c_str() );
		for( std::list<std::string>::iterator j = lTmp.begin();
			 j != lTmp.end(); j++ )
		{
			add( new Command( (Command::CmdType)(*i).first, (*j).c_str() ) );
		}
	}
	for( std::list<Command *>::iterator i = lCommand.begin();
		 i != lCommand.end(); i++ )
	{
		(*i)->execute( bld );
	}
}