[377] | 1 | // %flair:license{
|
---|
| 2 | // This file is part of the Flair framework distributed under the
|
---|
| 3 | // CECILL-C License, Version 1.0.
|
---|
| 4 | // %flair:license}
|
---|
| 5 | // created: 2020/12/16
|
---|
| 6 | // filename: UgvFactory.cpp
|
---|
| 7 | //
|
---|
| 8 | // author: Guillaume Sanahuja
|
---|
| 9 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
| 10 | //
|
---|
| 11 | // version: $Id: $
|
---|
| 12 | //
|
---|
| 13 | // purpose: construct a Ugv based on the type name
|
---|
| 14 | //
|
---|
| 15 | //
|
---|
| 16 | /*********************************************************************/
|
---|
| 17 |
|
---|
| 18 | #include "UgvFactory.h"
|
---|
| 19 | #include "FrameworkManager.h"
|
---|
| 20 | #include "SimuUgv.h"
|
---|
[378] | 21 | #include "SumoUgv.h"
|
---|
[377] | 22 |
|
---|
| 23 |
|
---|
| 24 | using namespace std;
|
---|
| 25 | using namespace flair::core;
|
---|
| 26 | using namespace flair::meta;
|
---|
| 27 |
|
---|
| 28 | namespace { // anonymous
|
---|
| 29 | vector<flair::meta::Ugv* (*)(string,string,string)> *vectoroffunctions=NULL;
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 |
|
---|
| 33 | Ugv *CreateUgv(string name, string type,string options) {
|
---|
| 34 |
|
---|
| 35 | Ugv *ugv;
|
---|
| 36 |
|
---|
| 37 | if(vectoroffunctions!=NULL) {
|
---|
| 38 | for(int i=0;i<vectoroffunctions->size();i++) {
|
---|
| 39 | ugv=vectoroffunctions->at(i)(name,type,options);
|
---|
| 40 | if(ugv!=NULL) {
|
---|
| 41 | free(vectoroffunctions);
|
---|
| 42 | vectoroffunctions=NULL;
|
---|
| 43 | return ugv;
|
---|
| 44 | }
|
---|
| 45 | }
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | #ifdef CORE2_64
|
---|
| 49 | if (type.compare(0, 8, "ugv_simu") == 0) {
|
---|
| 50 | int simu_id = 0;
|
---|
| 51 | if (type.size() > 8) {
|
---|
| 52 | simu_id = atoi(type.substr(8, type.size() - 8).c_str());
|
---|
| 53 | }
|
---|
| 54 | return new SimuUgv(name, simu_id);
|
---|
[378] | 55 | } else if (type.compare(0, 4, "sumo") == 0) {
|
---|
| 56 | return new SumoUgv(name);
|
---|
| 57 | } else {
|
---|
[377] | 58 | getFrameworkManager()->Err("UGV type %s unknown\n", type.c_str());
|
---|
| 59 | return NULL;
|
---|
| 60 | }
|
---|
| 61 | #endif
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | void RegisterUgvCreator(flair::meta::Ugv*(*func)(string,string,string)) {
|
---|
| 65 | if(vectoroffunctions==NULL) vectoroffunctions=(vector<flair::meta::Ugv* (*)(string,string,string)>*)malloc(sizeof(vector<flair::meta::Ugv* (*)(string,string,string)>));
|
---|
| 66 |
|
---|
| 67 | vectoroffunctions->push_back(func);
|
---|
| 68 | }
|
---|