Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/util/executor/executor.cc @ 5637

Last change on this file since 5637 was 5636, checked in by bensch, 20 years ago

orxonox/trunk: adapting ShellCommand to use Executor.
On the go

File size: 4.0 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Benjamin Grauer
13   co-programmer: ...
14*/
15
16//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
17
18#include "executor.h"
19
20#include "list.h"
21#include "debug.h"
22#include "class_list.h"
23
24#include "key_names.h"
25#include <stdarg.h>
26#include <stdio.h>
27#include <string.h>
28
29using namespace std;
30
31////////////////////////
32// SHELL COMMAND BASE //
33////////////////////////
34/**
35 * constructs and registers a new Command
36 * @param commandName the name of the Command
37 * @param className the name of the class to apply this command to
38 * @param paramCount the count of parameters this command takes
39 */
40Executor::Executor(unsigned int paramCount, ...)
41{
42  this->setClassID(CL_EXECUTOR, "Executor");
43
44  if (paramCount > FUNCTOR_MAX_ARGUMENTS)
45    paramCount = FUNCTOR_MAX_ARGUMENTS;
46  // reading in Parameters.
47  this->paramCount = paramCount;
48  this->defaultValue = new MultiType[paramCount];
49
50  va_list parameterList;
51  va_start(parameterList, paramCount);
52
53  // What Parameters we have got
54  for (unsigned int i = 0; i < paramCount; i++)
55    this->defaultValue[i].setType(va_arg(parameterList, int));
56}
57
58/**
59 * deconstructs a Executor
60 */
61Executor::~Executor()
62{
63  delete[] this->defaultValue;
64}
65
66/**
67 * sets default Values of the Commands
68 * @param count how many default Values to set.
69 * @param ... the default Values in order. They will be cast to the right type
70 * @returns itself
71 *
72 * Be aware, that when you use this Function, you !!MUST!! match the input as
73 * count, [EXACTLY THE SAME AS IF YOU WOULD CALL THE FUNCTION UP TO count ARGUMENTS]
74 */
75Executor* Executor::defaultValues(unsigned int count, ...)
76{
77  va_list values;
78  va_start(values, count);
79
80  this->defaultValues(count, values);
81}
82
83Executor* Executor::defaultValues(unsigned int count, va_list values)
84{
85  if (this == NULL)
86    return NULL;
87  if (count == 0)
88    return this;
89  if (count > this->paramCount)
90    count = this->paramCount;
91
92
93  for (unsigned int i = 0; i < count; i++)
94  {
95    switch (this->defaultValue[i].getType())
96    {
97      case MT_BOOL:
98        this->defaultValue[i].setInt(va_arg(values, int));
99        break;
100      case MT_CHAR:
101        this->defaultValue[i].setChar((char)va_arg(values, int));
102        break;
103      case MT_STRING:
104        this->defaultValue[i].setString(va_arg(values, char*));
105        break;
106      case MT_INT:
107        this->defaultValue[i].setInt(va_arg(values, int));
108        break;
109/*      case MT_UINT:
110        this->defaultValue[i].setInt((int)va_arg(values, unsigned int));
111        break;*/
112      case MT_FLOAT:
113        this->defaultValue[i].setFloat(va_arg(values, double));
114        break;
115/*      case MT_LONG:
116        this->defaultValue[i].setInt((int) va_arg(values, long));
117        break;*/
118      default:
119        break;
120    }
121  }
122  return this;
123}
124
125/**
126 * prints out nice information about the Executor
127 */
128void Executor::debug()
129{
130/*  tIterator<ExecutorClass>* iteratorCL = ExecutorClass::commandClassList->getIterator();
131  ExecutorClass* elemCL = iteratorCL->firstElement();
132  while(elemCL != NULL)
133  {
134    PRINT(0)("Class:'%s' registered %d commands: \n", elemCL->className, elemCL->commandList->getSize());
135    tIterator<Executor>* iterator = elemCL->commandList->getIterator();
136    const Executor* elem = iterator->firstElement();
137    while(elem != NULL)
138    {
139      PRINT(0)("  command:'%s' : params:%d: ", elem->getName(), elem->paramCount);
140      for (unsigned int i = 0; i< elem->paramCount; i++)
141       printf("%s ", Executor::paramToString(elem->parameters[i]));
142      if (elem->description != NULL)
143       printf("- %s", elem->description);
144      printf("\n");
145
146      elem = iterator->nextElement();
147    }
148    delete iterator;
149    elemCL = iteratorCL->nextElement();
150  }
151  delete iteratorCL;*/
152}
Note: See TracBrowser for help on using the repository browser.