Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: new Default Values… they now too are in MultiType instead of (count, …) or (count, va_arg) style

File size: 4.0 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    if (this->defaultValue[i] == MT_NULL)
58    {
59      this->paramCount = i;
60      break;
61    }
62  }
63  assert (paramCount <= FUNCTOR_MAX_ARGUMENTS);
64}
65
66/**
67 * deconstructs a Executor
68 */
69Executor::~Executor()
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  for (unsigned int i = 0; i < this->paramCount; i++)
80    executor->defaultValue[i] =  this->defaultValue[i];
81}
82
83/**
84 * @brief set the default values of the executor
85 * @param value0 the first default value
86 * @param value1 the second default value
87 * @param value2 the third default value
88 * @param value3 the fourth default value
89 * @param value4 the fifth default value
90 * @returns itself
91 */
92Executor* Executor::defaultValues(const MultiType& value0,
93                                  const MultiType& value1,
94                                  const MultiType& value2,
95                                  const MultiType& value3,
96                                  const MultiType& value4)
97{
98  if (this == NULL)
99    return NULL;
100
101  const MultiType* value[5];
102  value[0] = &value0;
103  value[1] = &value1;
104  value[2] = &value2;
105  value[3] = &value3;
106  value[4] = &value4;
107
108  for (unsigned int i = 0; i < this->paramCount; i++)
109  {
110    if (*value[i] != MT_NULL)
111    {
112      if (this->defaultValue[i].getType() == value[i]->getType())
113      {
114        this->defaultValue[i] = *value[i];
115      }
116      else
117      {
118        PRINTF(1)("Unable to set this Value, as it is not of type %s\n", MultiType::MultiTypeToString(this->defaultValue[i].getType()));
119      }
120    }
121  }
122  return this;
123}
124
125/**
126 * prints out nice information about the Executor
127 */
128void Executor::debug()
129{
130  /*  tIterator<ExecutorClass>* iteratorCL = ExecutorClass::commandClassList->getIterator();
131    ExecutorClass* elemCL = iteratorCL->firstElement();
132    while(elemCL != NULL)
133    {
134      PRINT(0)("Class:'%s' registered %d commands: \n", elemCL->className, elemCL->commandList->getSize());
135      tIterator<Executor>* iterator = elemCL->commandList->getIterator();
136      const Executor* elem = iterator->firstElement();
137      while(elem != NULL)
138      {
139        PRINT(0)("  command:'%s' : params:%d: ", elem->getName(), elem->paramCount);
140        for (unsigned int i = 0; i< elem->paramCount; i++)
141         printf("%s ", Executor::paramToString(elem->parameters[i]));
142        if (elem->description != NULL)
143         printf("- %s", elem->description);
144        printf("\n");
145
146        elem = iterator->nextElement();
147      }
148      delete iterator;
149      elemCL = iteratorCL->nextElement();
150    }
151    delete iteratorCL;*/
152}
Note: See TracBrowser for help on using the repository browser.