Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: Executor now uses MultiType instead of va_arg

File size: 4.5 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 "debug.h"
21#include "class_list.h"
22
23#include "key_names.h"
24#include <stdarg.h>
25#include <stdio.h>
26#include <string.h>
27
28using namespace std;
29
30////////////////////////
31// SHELL COMMAND BASE //
32////////////////////////
33/**
34 * constructs and registers a new Command
35 * @param commandName the name of the Command
36 * @param className the name of the class to apply this command to
37 * @param paramCount the count of parameters this command takes
38 */
39Executor::Executor(const MultiType& param0,
40                   const MultiType& param1,
41                   const MultiType& param2,
42                   const MultiType& param3,
43                   const MultiType& param4)
44{
45  this->setClassID(CL_EXECUTOR, "Executor");
46
47
48  // What Parameters have we got
49  this->defaultValue[0] = param0;
50  this->defaultValue[1] = param1;
51  this->defaultValue[2] = param2;
52  this->defaultValue[3] = param3;
53  this->defaultValue[4] = param4;
54
55  for (unsigned int i = 0; i < FUNCTOR_MAX_ARGUMENTS; i++)
56  {
57    printf("%d ", i);
58    if (this->defaultValue[i] == MT_NULL)
59    {
60      this->paramCount = i;
61      break;
62    }
63
64  }
65  printf("%d\n", this->paramCount);
66
67  assert (paramCount <= FUNCTOR_MAX_ARGUMENTS);
68}
69
70/**
71 * deconstructs a Executor
72 */
73Executor::~Executor()
74{}
75
76/**
77 * clones this element into executor.
78 */
79void Executor::cloning(Executor* executor) const
80{
81  executor->functorType  = this->functorType;
82  executor->paramCount   = this->paramCount;
83  for (unsigned int i = 0; i < this->paramCount; i++)
84    executor->defaultValue[i] =  this->defaultValue[i];
85}
86
87
88
89/**
90 * sets default Values of the Commands
91 * @param count how many default Values to set.
92 * @param ... the default Values in order. They will be cast to the right type
93 * @returns itself
94 *
95 * Be aware, that when you use this Function, you !!MUST!! match the input as
96 * count, [EXACTLY THE SAME AS IF YOU WOULD CALL THE FUNCTION UP TO count ARGUMENTS]
97 */
98Executor* Executor::defaultValues(unsigned int count, ...)
99{
100  va_list values;
101  va_start(values, count);
102
103  this->defaultValues(count, values);
104}
105
106Executor* Executor::defaultValues(unsigned int count, va_list values)
107{
108  if (this == NULL)
109    return NULL;
110  if (count == 0)
111    return this;
112  if (count > this->paramCount)
113    count = this->paramCount;
114
115
116  for (unsigned int i = 0; i < count; i++)
117  {
118    switch (this->defaultValue[i].getType())
119    {
120      case MT_BOOL:
121        this->defaultValue[i].setInt(va_arg(values, int));
122        break;
123      case MT_CHAR:
124        this->defaultValue[i].setChar((char)va_arg(values, int));
125        break;
126      case MT_STRING:
127        this->defaultValue[i].setString(va_arg(values, char*));
128        break;
129      case MT_INT:
130        this->defaultValue[i].setInt(va_arg(values, int));
131        break;
132        /*      case MT_UINT:
133                this->defaultValue[i].setInt((int)va_arg(values, unsigned int));
134                break;*/
135      case MT_FLOAT:
136        this->defaultValue[i].setFloat(va_arg(values, double));
137        break;
138        /*      case MT_LONG:
139                this->defaultValue[i].setInt((int) va_arg(values, long));
140                break;*/
141      default:
142        break;
143    }
144  }
145  return this;
146}
147
148/**
149 * prints out nice information about the Executor
150 */
151void Executor::debug()
152{
153  /*  tIterator<ExecutorClass>* iteratorCL = ExecutorClass::commandClassList->getIterator();
154    ExecutorClass* elemCL = iteratorCL->firstElement();
155    while(elemCL != NULL)
156    {
157      PRINT(0)("Class:'%s' registered %d commands: \n", elemCL->className, elemCL->commandList->getSize());
158      tIterator<Executor>* iterator = elemCL->commandList->getIterator();
159      const Executor* elem = iterator->firstElement();
160      while(elem != NULL)
161      {
162        PRINT(0)("  command:'%s' : params:%d: ", elem->getName(), elem->paramCount);
163        for (unsigned int i = 0; i< elem->paramCount; i++)
164         printf("%s ", Executor::paramToString(elem->parameters[i]));
165        if (elem->description != NULL)
166         printf("- %s", elem->description);
167        printf("\n");
168
169        elem = iterator->nextElement();
170      }
171      delete iterator;
172      elemCL = iteratorCL->nextElement();
173    }
174    delete iteratorCL;*/
175}
Note: See TracBrowser for help on using the repository browser.