Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: Passing Reference inastead of Pointer to create ShellCommand

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