Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/spaceshipcontrol/src/lib/util/executor/executor.cc @ 6177

Last change on this file since 6177 was 5659, checked in by bensch, 19 years ago

orxonox/trunk: valgrind sweep - no more Use of Uninitialized Value in MultiType

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