Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/util/shell_command.cc @ 5130

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

orxonox/trunk: flush

File size: 2.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 "shell_command.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
28using namespace std;
29
30ShellCommandBase::ShellCommandBase(const char* commandName, ClassID classID, void* functionPointer, unsigned int paramCount, va_list parameters)
31{
32  this->classID = classID;
33  this->functionPointer = functionPointer;
34  this->commandName = new char[strlen(commandName)+1];
35  strcpy(this->commandName, commandName);
36
37  // handling parameters, and storing them:
38  this->paramCount = paramCount;
39  this->parameters = new ShellParameterType[paramCount];
40
41  for (unsigned int i = 0; i < paramCount; i++)
42    parameters[i] = va_arg(parameters, long);
43
44  // adding this ShellCommand to the list of known Commands
45  ShellCommandBase::commandList->add(this);
46}
47
48ShellCommandBase::~ShellCommandBase()
49{
50  delete[] this->commandName;
51  delete[] this->parameters;
52}
53
54
55tList<ShellCommandBase>* ShellCommandBase::commandList = NULL;
56
57bool ShellCommandBase::isRegistered(const char* commandName, ClassID classID, unsigned int paramCount, va_list parameters)
58{
59  if (ShellCommandBase::commandList == NULL)
60  {
61    ShellCommandBase::commandList = new tList<ShellCommandBase>;
62    return false;
63  }
64
65  tIterator<ShellCommandBase>* iterator = ShellCommandBase::commandList->getIterator();
66  ShellCommandBase* elem = iterator->firstElement();
67  while(elem != NULL)
68  {
69    if (classID == elem->classID && !strcmp(commandName, elem->commandName))
70    {
71//      PRINTF(2)("Command already registered\n");
72      delete iterator;
73      return true;
74    }
75    elem = iterator->nextElement();
76  }
77  delete iterator;
78  return true;
79}
80
81
Note: See TracBrowser for help on using the repository browser.