source: src/base/command_list.cpp@ 884223

Last change on this file since 884223 was 48b662, checked in by Olaf Lenz <olenz@…>, 14 years ago

Moved files in scafacos_fcs one level up.

git-svn-id: https://svn.version.fz-juelich.de/scafacos/trunk@847 5161e1c8-67bf-11de-9fd5-51895aff932f

  • Property mode set to 100644
File size: 1.7 KB
Line 
1/**
2 * @file command_list.cpp
3 * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
4 * @date Tue Apr 5 20:15:06 2011
5 *
6 */
7
8#ifdef HAVE_CONFIG_H
9#include <config.h>
10#endif
11
12#include <cstdio>
13
14#include "base/command.hpp"
15#include "base/command_list.hpp"
16#include "base/defs.hpp"
17#include "mg.hpp"
18
19using namespace VMG;
20
21Request CommandList::ExecuteList()
22{
23 Request request;
24 Request final_request = (commands.size() == 0 ? StopCycleNow : Continue);
25
26 for (CommandList::iterator iter=commands.begin(); iter!=commands.end(); ++iter) {
27
28#ifdef DEBUG
29 const int num_args = (iter->second.size() > 1 ? iter->second.size() : (iter->second[0] == "" ? 0 : 1));
30 MG::GetFactory().CheckNumberOfArguments(iter->first, num_args);
31#endif
32
33 request = MG::GetFactory().GetCommand((*iter).first)->Run((*iter).second);
34
35 if (request == StopCycleLater)
36 final_request = StopCycleNow;
37 else if (request == StopCycleNow) {
38 final_request = StopCycleNow;
39 break;
40 }
41 }
42
43 return final_request;
44}
45
46void CommandList::AddCommand(std::string command, std::string arguments)
47{
48 std::vector<std::string> argument_list;
49 size_t pos;
50
51 do {
52 pos = arguments.find(':');
53 argument_list.push_back(arguments.substr(0, pos));
54 arguments.erase(0, pos+1);
55 }while (pos != std::string::npos);
56
57 commands.push_back(std::pair<std::string, std::vector<std::string> >(command, argument_list));
58}
59
60void CommandList::DeleteCommand(const CommandList::iterator& iter)
61{
62 commands.erase(iter);
63}
64
65void CommandList::Print()
66{
67 for (CommandList::iterator iter=commands.begin(); iter!=commands.end(); ++iter)
68 printf("%s\n", (*iter).first.c_str());
69}
70
71void CommandList::Clear()
72{
73 commands.clear();
74}
Note: See TracBrowser for help on using the repository browser.