Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: more about the executor.

File size: 4.1 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 * sets default Values of the Commands
71 * @param count how many default Values to set.
72 * @param ... the default Values in order. They will be cast to the right type
73 * @returns itself
74 *
75 * Be aware, that when you use this Function, you !!MUST!! match the input as
76 * count, [EXACTLY THE SAME AS IF YOU WOULD CALL THE FUNCTION UP TO count ARGUMENTS]
77 */
78Executor* Executor::defaultValues(unsigned int count, ...)
79{
80  va_list values;
81  va_start(values, count);
82
83  this->defaultValues(count, values);
84}
85
86Executor* Executor::defaultValues(unsigned int count, va_list values)
87{
88  if (this == NULL)
89    return NULL;
90  if (count == 0)
91    return this;
92  if (count > this->paramCount)
93    count = this->paramCount;
94
95
96  for (unsigned int i = 0; i < count; i++)
97  {
98    switch (this->defaultValue[i].getType())
99    {
100      case MT_BOOL:
101        this->defaultValue[i].setInt(va_arg(values, int));
102        break;
103      case MT_CHAR:
104        this->defaultValue[i].setChar((char)va_arg(values, int));
105        break;
106      case MT_STRING:
107        this->defaultValue[i].setString(va_arg(values, char*));
108        break;
109      case MT_INT:
110        this->defaultValue[i].setInt(va_arg(values, int));
111        break;
112/*      case MT_UINT:
113        this->defaultValue[i].setInt((int)va_arg(values, unsigned int));
114        break;*/
115      case MT_FLOAT:
116        this->defaultValue[i].setFloat(va_arg(values, double));
117        break;
118/*      case MT_LONG:
119        this->defaultValue[i].setInt((int) va_arg(values, long));
120        break;*/
121      default:
122        break;
123    }
124  }
125  return this;
126}
127
128/**
129 * prints out nice information about the Executor
130 */
131void Executor::debug()
132{
133/*  tIterator<ExecutorClass>* iteratorCL = ExecutorClass::commandClassList->getIterator();
134  ExecutorClass* elemCL = iteratorCL->firstElement();
135  while(elemCL != NULL)
136  {
137    PRINT(0)("Class:'%s' registered %d commands: \n", elemCL->className, elemCL->commandList->getSize());
138    tIterator<Executor>* iterator = elemCL->commandList->getIterator();
139    const Executor* elem = iterator->firstElement();
140    while(elem != NULL)
141    {
142      PRINT(0)("  command:'%s' : params:%d: ", elem->getName(), elem->paramCount);
143      for (unsigned int i = 0; i< elem->paramCount; i++)
144       printf("%s ", Executor::paramToString(elem->parameters[i]));
145      if (elem->description != NULL)
146       printf("- %s", elem->description);
147      printf("\n");
148
149      elem = iterator->nextElement();
150    }
151    delete iterator;
152    elemCL = iteratorCL->nextElement();
153  }
154  delete iteratorCL;*/
155}
Note: See TracBrowser for help on using the repository browser.