Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5633 was 5633, checked in by bensch, 18 years ago

orxonox/trunk: Executor works just fine.
Changed: Paramerte* to MT_*, to make things more general

File size: 4.3 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(const char* commandName, const char* className, unsigned int paramCount, ...)
41{
42  this->setClassID(CL_EXECUTOR, "Executor");
43  this->setName(commandName);
44
45//  this->classID = classID;
46  // handling parameters, and storing them:
47  if (paramCount > FUNCTOR_MAX_ARGUMENTS)
48    paramCount = FUNCTOR_MAX_ARGUMENTS;
49  // reading in Parameters.
50  this->paramCount = paramCount;
51  this->defaultValue = new MultiType[paramCount];
52
53  va_list parameterList;
54  va_start(parameterList, paramCount);
55
56  // What Parameters we have got
57  for (unsigned int i = 0; i < paramCount; i++)
58    this->defaultValue[i].setType(va_arg(parameterList, int));
59}
60
61/**
62 * deconstructs a Executor
63 */
64Executor::~Executor()
65{
66  delete[] this->defaultValue;
67}
68
69/**
70 * lets a command be described
71 * @param description the description of the Given command
72 */
73Executor* Executor::describe(const char* description)
74{
75  if (this == NULL)
76    return NULL;
77 else
78 {
79   this->description = description;
80   return this;
81 }
82}
83
84/**
85 * sets default Values of the Commands
86 * @param count how many default Values to set.
87 * @param ... the default Values in order. They will be cast to the right type
88 * @returns itself
89 *
90 * Be aware, that when you use this Function, you !!MUST!! match the input as
91 * count, [EXACTLY THE SAME AS IF YOU WOULD CALL THE FUNCTION UP TO count ARGUMENTS]
92 */
93Executor* Executor::defaultValues(unsigned int count, ...)
94{
95  if (this == NULL)
96    return NULL;
97  if (count == 0)
98    return this;
99  if (count > this->paramCount)
100    count = this->paramCount;
101
102  va_list defaultList;
103  va_start(defaultList, count);
104
105  for (unsigned int i = 0; i < count; i++)
106  {
107    switch (this->defaultValue[i].getType())
108    {
109      case MT_BOOL:
110        this->defaultValue[i].setInt(va_arg(defaultList, int));
111        break;
112      case MT_CHAR:
113        this->defaultValue[i].setChar((char)va_arg(defaultList, int));
114        break;
115      case MT_STRING:
116        this->defaultValue[i].setString(va_arg(defaultList, char*));
117        break;
118      case MT_INT:
119        this->defaultValue[i].setInt(va_arg(defaultList, int));
120        break;
121/*      case MT_UINT:
122        this->defaultValue[i].setInt((int)va_arg(defaultList, unsigned int));
123        break;*/
124      case MT_FLOAT:
125        this->defaultValue[i].setFloat(va_arg(defaultList, double));
126        break;
127/*      case MT_LONG:
128        this->defaultValue[i].setInt((int) va_arg(defaultList, long));
129        break;*/
130      default:
131        break;
132    }
133  }
134  return this;
135}
136
137/**
138 * prints out nice information about the Executor
139 */
140void Executor::debug()
141{
142/*  tIterator<ExecutorClass>* iteratorCL = ExecutorClass::commandClassList->getIterator();
143  ExecutorClass* elemCL = iteratorCL->firstElement();
144  while(elemCL != NULL)
145  {
146    PRINT(0)("Class:'%s' registered %d commands: \n", elemCL->className, elemCL->commandList->getSize());
147    tIterator<Executor>* iterator = elemCL->commandList->getIterator();
148    const Executor* elem = iterator->firstElement();
149    while(elem != NULL)
150    {
151      PRINT(0)("  command:'%s' : params:%d: ", elem->getName(), elem->paramCount);
152      for (unsigned int i = 0; i< elem->paramCount; i++)
153       printf("%s ", Executor::paramToString(elem->parameters[i]));
154      if (elem->description != NULL)
155       printf("- %s", elem->description);
156      printf("\n");
157
158      elem = iterator->nextElement();
159    }
160    delete iterator;
161    elemCL = iteratorCL->nextElement();
162  }
163  delete iteratorCL;*/
164}
Note: See TracBrowser for help on using the repository browser.