From 79115386afc1dee957f77e9a82b5b9b2c5f347e6 Mon Sep 17 00:00:00 2001 From: sicarius Date: Tue, 16 Jan 2007 16:10:05 +0000 Subject: Changed some things in Concept directory --- source/Concept/Framework/Concept.vcproj | 208 ++++++++++++++++++++++++++++++++ source/Concept/Framework/defines.h | 91 ++++++++++++++ source/Concept/Framework/engine.cpp | 1 + source/Concept/Framework/engine.h | 19 +++ source/Concept/Framework/io_module.cpp | 1 + source/Concept/Framework/io_module.h | 29 +++++ source/Concept/Framework/main.cpp | 47 ++++++++ source/Concept/Framework/module.cpp | 0 source/Concept/Framework/module.h | 0 source/Concept/Framework/robot.cpp | 37 ++++++ source/Concept/Framework/robot.h | 46 +++++++ source/Concept/Framework/sensor.cpp | 1 + source/Concept/Framework/sensor.h | 29 +++++ source/Concept/Framework/stdafx.h | 12 ++ 14 files changed, 521 insertions(+) create mode 100644 source/Concept/Framework/Concept.vcproj create mode 100644 source/Concept/Framework/defines.h create mode 100644 source/Concept/Framework/engine.cpp create mode 100644 source/Concept/Framework/engine.h create mode 100644 source/Concept/Framework/io_module.cpp create mode 100644 source/Concept/Framework/io_module.h create mode 100644 source/Concept/Framework/main.cpp create mode 100644 source/Concept/Framework/module.cpp create mode 100644 source/Concept/Framework/module.h create mode 100644 source/Concept/Framework/robot.cpp create mode 100644 source/Concept/Framework/robot.h create mode 100644 source/Concept/Framework/sensor.cpp create mode 100644 source/Concept/Framework/sensor.h create mode 100644 source/Concept/Framework/stdafx.h (limited to 'source/Concept/Framework') diff --git a/source/Concept/Framework/Concept.vcproj b/source/Concept/Framework/Concept.vcproj new file mode 100644 index 0000000..61c34c2 --- /dev/null +++ b/source/Concept/Framework/Concept.vcproj @@ -0,0 +1,208 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/source/Concept/Framework/defines.h b/source/Concept/Framework/defines.h new file mode 100644 index 0000000..698163a --- /dev/null +++ b/source/Concept/Framework/defines.h @@ -0,0 +1,91 @@ +#ifndef _DEFINES_H +#define _DEFINES_H + +#ifndef NULL +#define NULL 0 +#endif + +//Integer definition +#ifndef int8 + #ifdef __int8 + #define int8 __int8 + #else + #define int8 char + #endif +#endif + +#ifndef int16 + #ifdef __int16 + #define int16 __int16 + #else + #define int16 int + #endif +#endif + +#ifndef int32 + #ifdef __int32 + #define int32 __int32 + #else + #define int32 long + #endif +#endif + +#ifndef int64 + #ifdef __int64 + #define int64 __int64 + #else + #define int64 long long + #endif +#endif + +//Unsigned +#ifndef uint8 +#define uint8 unsigned int8 +#endif + +#ifndef uint16 +#define uint16 unsigned int16 +#endif + +#ifndef uint32 +#define uint32 unsigned int32 +#endif + +#ifndef uint64 +#define uint64 unsigned int64 +#endif + +//Sensor types +enum SensorTypes +{ + SENSOR_TYPE_ANALOG, + SENSOR_TYPE_DIGITAL, +}; + +//IO Module Names +enum IOModuleNames +{ + //General + IO_START, + + //Engines + IO_ENGINE_START = IO_START, + + IO_ENGINE_DRIVE_LEFT = IO_ENGINE_START, + IO_ENGINE_DRIVE_RIGHT, + IO_ENGINE_DRIVE_BACK, + + IO_ENGINE_END, + + //Sensors + IO_SENSOR_START = IO_ENGINE_END, + + IO_SENSOR_MOUSE = IO_SENSOR_START, + + IO_SENSOR_END, + + //General + IO_END = IO_SENSOR_END, +}; + +#endif \ No newline at end of file diff --git a/source/Concept/Framework/engine.cpp b/source/Concept/Framework/engine.cpp new file mode 100644 index 0000000..11856cc --- /dev/null +++ b/source/Concept/Framework/engine.cpp @@ -0,0 +1 @@ +#include "engine.h" \ No newline at end of file diff --git a/source/Concept/Framework/engine.h b/source/Concept/Framework/engine.h new file mode 100644 index 0000000..406d46e --- /dev/null +++ b/source/Concept/Framework/engine.h @@ -0,0 +1,19 @@ +#ifndef _ENGINE_H +#define _ENGINE_H + +#include "stdafx.h" + +class Engine : public IO_Module +{ +public: + Engine() + { + } + + Engine(uint32 engineId) + { + this->moduleId = engineId; + } +}; + +#endif \ No newline at end of file diff --git a/source/Concept/Framework/io_module.cpp b/source/Concept/Framework/io_module.cpp new file mode 100644 index 0000000..93f78ae --- /dev/null +++ b/source/Concept/Framework/io_module.cpp @@ -0,0 +1 @@ +#include "io_module.h" \ No newline at end of file diff --git a/source/Concept/Framework/io_module.h b/source/Concept/Framework/io_module.h new file mode 100644 index 0000000..8aa7ef7 --- /dev/null +++ b/source/Concept/Framework/io_module.h @@ -0,0 +1,29 @@ +#ifndef _MODULE_H +#define _MODULE_H + +#include "defines.h" + +class IO_Module +{ +public: + IO_Module(uint32 moduleId) + { + this->moduleId = moduleId; + } + + IO_Module(){} + +protected: + uint32 moduleId; + +public: + + uint32 GetId() + { + return moduleId; + } + + +}; + +#endif \ No newline at end of file diff --git a/source/Concept/Framework/main.cpp b/source/Concept/Framework/main.cpp new file mode 100644 index 0000000..6305a1e --- /dev/null +++ b/source/Concept/Framework/main.cpp @@ -0,0 +1,47 @@ +#include "stdafx.h" + +int main() +{ + //Init our robot + Robot* localRobot = new Robot(); + + //Init Engines + for(uint8 i = IO_ENGINE_START; i < IO_ENGINE_END; i++) + { + Engine* newEngine = new Engine(i); + localRobot->AddModule(newEngine); + newEngine = NULL; + } + + //Init Sensors + for(uint8 i = IO_SENSOR_START; i < IO_SENSOR_END; i++) + { + SensorTypes newSensorType; + + switch(i) + { + //Cases when sensor is digital: + // newSensorType = SENSOR_TYPE_DIGITAL; + // break; + + //Other cases + default: + newSensorType = SENSOR_TYPE_ANALOG; + break; + } + + Sensor* newSensor = new Sensor(i, newSensorType); + localRobot->AddModule(newSensor); + newSensor = NULL; + } + + //Run + while(true) + { + localRobot->Update(); + } + + //Cleanup + delete localRobot; + localRobot = NULL; +} \ No newline at end of file diff --git a/source/Concept/Framework/module.cpp b/source/Concept/Framework/module.cpp new file mode 100644 index 0000000..e69de29 diff --git a/source/Concept/Framework/module.h b/source/Concept/Framework/module.h new file mode 100644 index 0000000..e69de29 diff --git a/source/Concept/Framework/robot.cpp b/source/Concept/Framework/robot.cpp new file mode 100644 index 0000000..768554e --- /dev/null +++ b/source/Concept/Framework/robot.cpp @@ -0,0 +1,37 @@ +#include "robot.h" + +//----------------------------------------------------------------------------- +Robot::~Robot() +{ + while(!modules.empty()) + { + moduleMap::iterator iter = modules.begin(); + delete iter->second; + modules.erase(iter); + } +} + +//----------------------------------------------------------------------------- +bool Robot::AddModule(IO_Module* newModule) +{ + moduleMap::iterator itr = modules.find(newModule->GetId()); + if(itr != modules.end()) + return false; + + modules[newModule->GetId()] = newModule; + return true; +} + +//----------------------------------------------------------------------------- +bool Robot::RemoveModule(IO_Module* oldModule) +{ + return RemoveModule(oldModule->GetId()); +} + +//----------------------------------------------------------------------------- +void Robot::Update() +{ + //insert code here +} + +//--- EOF --- \ No newline at end of file diff --git a/source/Concept/Framework/robot.h b/source/Concept/Framework/robot.h new file mode 100644 index 0000000..543f1ed --- /dev/null +++ b/source/Concept/Framework/robot.h @@ -0,0 +1,46 @@ +#ifndef _ROBOT_H +#define _ROBOT_H + +#include "stdafx.h" + +class IO_Module; +class Sensor; +class Engine; + +class Robot +{ +public: + ~Robot(); + +private: + typedef hash_map moduleMap; + moduleMap modules; + +public: + bool AddModule(IO_Module* newModule); + + template T* GetModule(uint32 moduleId) + { + moduleMap::const_iterator itr = modules.find(moduleId); + if(itr == modules.end()) + return NULL; + else + return ((T*)itr->second); + } + + bool RemoveModule(uint32 moduleId) + { + moduleMap::iterator itr = modules.find(moduleId); + if(itr == modules.end()) + return false; + + modules.erase(itr); + return true; + } + + bool RemoveModule(IO_Module* oldModule); + + void Update(); +}; + +#endif \ No newline at end of file diff --git a/source/Concept/Framework/sensor.cpp b/source/Concept/Framework/sensor.cpp new file mode 100644 index 0000000..b9b4936 --- /dev/null +++ b/source/Concept/Framework/sensor.cpp @@ -0,0 +1 @@ +#include "sensor.h" \ No newline at end of file diff --git a/source/Concept/Framework/sensor.h b/source/Concept/Framework/sensor.h new file mode 100644 index 0000000..23e40e9 --- /dev/null +++ b/source/Concept/Framework/sensor.h @@ -0,0 +1,29 @@ +#ifndef _SENSOR_H +#define _SENSOR_H + +#include "stdafx.h" + +class Sensor : public IO_Module +{ +public: + Sensor() + { + } + + Sensor(uint32 sensorId, SensorTypes sensorType) + { + this->moduleId = sensorId; + this->sensorType = sensorType; + } + +protected: + SensorTypes sensorType; + +public: + SensorTypes GetType() + { + return sensorType; + } +}; + +#endif \ No newline at end of file diff --git a/source/Concept/Framework/stdafx.h b/source/Concept/Framework/stdafx.h new file mode 100644 index 0000000..0a5a81e --- /dev/null +++ b/source/Concept/Framework/stdafx.h @@ -0,0 +1,12 @@ +#include +#include +#include +#include + +using namespace std; + +#include "defines.h" +#include "io_module.h" +#include "sensor.h" +#include "engine.h" +#include "robot.h" \ No newline at end of file -- cgit v1.2.3