O
oktayarslan
Hi all;
I have a problem when inserting an element to a vector. All I want is
reading some data from a file and putting them into a vector. But the
program is crashing after pushing a data which has string value. I
really do not understand why push_back() function is trying to remove
previously inserted data.
Thanks for any help
yatko
// program
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cstdlib>
#include <string.h>
class VLProperty
{
public:
enum Aircraft{
BO105,
F16
};
enum Type{
INT,
BOOL,
LONG,
FLOAT,
DOUBLE,
STRING,
UNSPECIFIED
};
};
struct VLPropertyData {
unsigned id;
// While the type isn't transmitted, it is needed for the destructor
VLProperty::Type type;
union{
int int_value;
float float_value;
char* string_value;
};
//std::string string_value;
VLPropertyData()
{
std::cout << "new data\n";
}
~VLPropertyData() {
if ((type == VLProperty::STRING) || (type ==
VLProperty::UNSPECIFIED))
{
std::cout << string_value << " is deleted" << std::endl;
delete [] string_value;
}
}
};
class VLAIMultiplayer;
class VLAIManager
{
public:
static std::string sAircraftIdList[];
static std::map<std::string,std::string> sAircraftModelNameMap;
/// maps from the aircraft string to the VLPropertyData vector
typedef std::map< std::string, std::vector <VLPropertyData>* >
ModelPropertyDataMap;
//static ModelPropertyDataMap sModelPropertyDataMap;
static ModelPropertyDataMap sAircraftPropertyDataMap;
VLAIManager();
~VLAIManager();
VLAIMultiplayer* addMultiplayer(const std::string& callsign, const
std::string& aircraft);
std::vector <VLPropertyData>
addProperties(const std::string& aircraft);
private:
/// maps from the callsign string to the VLAIMultiplayer
typedef std::map<std::string, VLAIMultiplayer* > MultiPlayerMap;
MultiPlayerMap mMultiPlayerMap;
};
struct VLExternalMotionInfo;
class VLMultiplayMgr
{
public:
struct PropertyDesc{
PropertyDesc()
{};
PropertyDesc(const char* name, VLProperty::Type type)
{
this->name = name;
this->type = type;
};
~PropertyDesc()
{};
const char* name;
VLProperty::Type type;
};
typedef std::map<unsigned int, PropertyDesc> IdPropertyDescMap;
static IdPropertyDescMap sIdPropertyDescMap;
static void Init();
private:
/// maps from the callsign string to the FGAIMultiplayer
typedef std::map<std::string, VLAIMultiplayer* > MultiPlayerMap;
MultiPlayerMap mMultiPlayerMap;
};
std::string VLAIManager::sAircraftIdList [] = {
"",
"t38",
"bo105",
"F16",
"b1900d"
};
VLMultiplayMgr::IdPropertyDescMap VLMultiplayMgr::sIdPropertyDescMap =
VLMultiplayMgr::IdPropertyDescMap();
void
VLMultiplayMgr::Init()
{
sIdPropertyDescMap[100] = VLMultiplayMgr:ropertyDesc("surface-
positions/left-aileron-pos-norm", VLProperty::FLOAT);
sIdPropertyDescMap[101] = VLMultiplayMgr:ropertyDesc("surface-
positions/right-aileron-pos-norm", VLProperty::FLOAT);
sIdPropertyDescMap[102] = VLMultiplayMgr:ropertyDesc("surface-
positions/elevator-pos-norm", VLProperty::FLOAT);
sIdPropertyDescMap[103] = VLMultiplayMgr:ropertyDesc("surface-
positions/rudder-pos-norm", VLProperty::FLOAT);
sIdPropertyDescMap[104] = VLMultiplayMgr:ropertyDesc("surface-
positions/flap-pos-norm", VLProperty::FLOAT);
sIdPropertyDescMap[105] = VLMultiplayMgr:ropertyDesc("surface-
positions/speedbrake-pos-norm", VLProperty::FLOAT);
sIdPropertyDescMap[106] = VLMultiplayMgr:ropertyDesc("gear/tailhook/
position-norm", VLProperty::FLOAT);
sIdPropertyDescMap[107] = VLMultiplayMgr:ropertyDesc("gear/
launchbar/position-norm", VLProperty::FLOAT);
sIdPropertyDescMap[108] = VLMultiplayMgr:ropertyDesc("gear/
launchbar/state", VLProperty::STRING);
sIdPropertyDescMap[109] = VLMultiplayMgr:ropertyDesc("gear/
launchbar/holdback-position-norm", VLProperty::FLOAT);
sIdPropertyDescMap[110] = VLMultiplayMgr:ropertyDesc("canopy/
position-norm", VLProperty::FLOAT);
sIdPropertyDescMap[200] = VLMultiplayMgr:ropertyDesc("gear/gear[0]/
compression-norm", VLProperty::FLOAT);
sIdPropertyDescMap[201] = VLMultiplayMgr:ropertyDesc("gear/gear[0]/
position-norm", VLProperty::FLOAT);
sIdPropertyDescMap[210] = VLMultiplayMgr:ropertyDesc("gear/gear[1]/
compression-norm", VLProperty::FLOAT);
sIdPropertyDescMap[211] = VLMultiplayMgr:ropertyDesc("gear/gear[1]/
position-norm", VLProperty::FLOAT);
sIdPropertyDescMap[220] = VLMultiplayMgr:ropertyDesc("gear/gear[2]/
compression-norm", VLProperty::FLOAT);
sIdPropertyDescMap[221] = VLMultiplayMgr:ropertyDesc("gear/gear[2]/
position-norm", VLProperty::FLOAT);
sIdPropertyDescMap[230] = VLMultiplayMgr:ropertyDesc("gear/gear[3]/
compression-norm", VLProperty::FLOAT);
sIdPropertyDescMap[231] = VLMultiplayMgr:ropertyDesc("gear/gear[3]/
position-norm", VLProperty::FLOAT);
sIdPropertyDescMap[240] = VLMultiplayMgr:ropertyDesc("gear/gear[4]/
compression-norm", VLProperty::FLOAT);
sIdPropertyDescMap[241] = VLMultiplayMgr:ropertyDesc("gear/gear[4]/
position-norm", VLProperty::FLOAT);
sIdPropertyDescMap[300] = VLMultiplayMgr:ropertyDesc("engines/
engine[0]/n1", VLProperty::FLOAT);
sIdPropertyDescMap[301] = VLMultiplayMgr:ropertyDesc("engines/
engine[0]/n2", VLProperty::FLOAT);
sIdPropertyDescMap[302] = VLMultiplayMgr:ropertyDesc("engines/
engine[0]/rpm", VLProperty::FLOAT);
sIdPropertyDescMap[310] = VLMultiplayMgr:ropertyDesc("engines/
engine[1]/n1", VLProperty::FLOAT);
sIdPropertyDescMap[311] = VLMultiplayMgr:ropertyDesc("engines/
engine[1]/n2", VLProperty::FLOAT);
sIdPropertyDescMap[312] = VLMultiplayMgr:ropertyDesc("engines/
engine[1]/rpm", VLProperty::FLOAT);
sIdPropertyDescMap[320] = VLMultiplayMgr:ropertyDesc("engines/
engine[2]/n1", VLProperty::FLOAT);
sIdPropertyDescMap[321] = VLMultiplayMgr:ropertyDesc("engines/
engine[2]/n2", VLProperty::FLOAT);
sIdPropertyDescMap[322] = VLMultiplayMgr:ropertyDesc("engines/
engine[2]/rpm", VLProperty::FLOAT);
sIdPropertyDescMap[330] = VLMultiplayMgr:ropertyDesc("engines/
engine[3]/n1", VLProperty::FLOAT);
sIdPropertyDescMap[331] = VLMultiplayMgr:ropertyDesc("engines/
engine[3]/n2", VLProperty::FLOAT);
sIdPropertyDescMap[332] = VLMultiplayMgr:ropertyDesc("engines/
engine[3]/rpm", VLProperty::FLOAT);
sIdPropertyDescMap[340] = VLMultiplayMgr:ropertyDesc("engines/
engine[4]/n1", VLProperty::FLOAT);
sIdPropertyDescMap[341] = VLMultiplayMgr:ropertyDesc("engines/
engine[4]/n2", VLProperty::FLOAT);
sIdPropertyDescMap[342] = VLMultiplayMgr:ropertyDesc("engines/
engine[4]/rpm", VLProperty::FLOAT);
sIdPropertyDescMap[350] = VLMultiplayMgr:ropertyDesc("engines/
engine[5]/n1", VLProperty::FLOAT);
sIdPropertyDescMap[351] = VLMultiplayMgr:ropertyDesc("engines/
engine[5]/n2", VLProperty::FLOAT);
sIdPropertyDescMap[352] = VLMultiplayMgr:ropertyDesc("engines/
engine[5]/rpm", VLProperty::FLOAT);
sIdPropertyDescMap[360] = VLMultiplayMgr:ropertyDesc("engines/
engine[6]/n1", VLProperty::FLOAT);
sIdPropertyDescMap[361] = VLMultiplayMgr:ropertyDesc("engines/
engine[6]/n2", VLProperty::FLOAT);
sIdPropertyDescMap[362] = VLMultiplayMgr:ropertyDesc("engines/
engine[6]/rpm", VLProperty::FLOAT);
sIdPropertyDescMap[370] = VLMultiplayMgr:ropertyDesc("engines/
engine[7]/n1", VLProperty::FLOAT);
sIdPropertyDescMap[371] = VLMultiplayMgr:ropertyDesc("engines/
engine[7]/n2", VLProperty::FLOAT);
sIdPropertyDescMap[372] = VLMultiplayMgr:ropertyDesc("engines/
engine[7]/rpm", VLProperty::FLOAT);
sIdPropertyDescMap[380] = VLMultiplayMgr:ropertyDesc("engines/
engine[8]/n1", VLProperty::FLOAT);
sIdPropertyDescMap[381] = VLMultiplayMgr:ropertyDesc("engines/
engine[8]/n2", VLProperty::FLOAT);
sIdPropertyDescMap[382] = VLMultiplayMgr:ropertyDesc("engines/
engine[8]/rpm", VLProperty::FLOAT);
sIdPropertyDescMap[390] = VLMultiplayMgr:ropertyDesc("engines/
engine[9]/n1", VLProperty::FLOAT);
sIdPropertyDescMap[391] = VLMultiplayMgr:ropertyDesc("engines/
engine[9]/n2", VLProperty::FLOAT);
sIdPropertyDescMap[392] = VLMultiplayMgr:ropertyDesc("engines/
engine[9]/rpm", VLProperty::FLOAT);
sIdPropertyDescMap[800] = VLMultiplayMgr:ropertyDesc("rotors/main/
rpm", VLProperty::FLOAT);
sIdPropertyDescMap[801] = VLMultiplayMgr:ropertyDesc("rotors/tail/
rpm", VLProperty::FLOAT);
sIdPropertyDescMap[810] = VLMultiplayMgr:ropertyDesc("rotors/main/
blade[0]/position-deg", VLProperty::FLOAT);
sIdPropertyDescMap[811] = VLMultiplayMgr:ropertyDesc("rotors/main/
blade[1]/position-deg", VLProperty::FLOAT);
sIdPropertyDescMap[812] = VLMultiplayMgr:ropertyDesc("rotors/main/
blade[2]/position-deg", VLProperty::FLOAT);
sIdPropertyDescMap[813] = VLMultiplayMgr:ropertyDesc("rotors/main/
blade[3]/position-deg", VLProperty::FLOAT);
sIdPropertyDescMap[820] = VLMultiplayMgr:ropertyDesc("rotors/main/
blade[0]/flap-deg", VLProperty::FLOAT);
sIdPropertyDescMap[821] = VLMultiplayMgr:ropertyDesc("rotors/main/
blade[1]/flap-deg", VLProperty::FLOAT);
sIdPropertyDescMap[822] = VLMultiplayMgr:ropertyDesc("rotors/main/
blade[2]/flap-deg", VLProperty::FLOAT);
sIdPropertyDescMap[823] = VLMultiplayMgr:ropertyDesc("rotors/main/
blade[3]/flap-deg", VLProperty::FLOAT);
sIdPropertyDescMap[830] = VLMultiplayMgr:ropertyDesc("rotors/tail/
blade[0]/position-deg", VLProperty::FLOAT);
sIdPropertyDescMap[831] = VLMultiplayMgr:ropertyDesc("rotors/tail/
blade[1]/position-deg", VLProperty::FLOAT);
sIdPropertyDescMap[900] = VLMultiplayMgr:ropertyDesc("sim/hitches/
aerotow/tow/length", VLProperty::FLOAT);
sIdPropertyDescMap[901] = VLMultiplayMgr:ropertyDesc("sim/hitches/
aerotow/tow/elastic-constant", VLProperty::FLOAT);
sIdPropertyDescMap[902] = VLMultiplayMgr:ropertyDesc("sim/hitches/
aerotow/tow/weight-per-m-kg-m", VLProperty::FLOAT);
sIdPropertyDescMap[903] = VLMultiplayMgr:ropertyDesc("sim/hitches/
aerotow/tow/dist", VLProperty::FLOAT);
sIdPropertyDescMap[904] = VLMultiplayMgr:ropertyDesc("sim/hitches/
aerotow/tow/connected-to-property-node", VLProperty::BOOL);
sIdPropertyDescMap[905] = VLMultiplayMgr:ropertyDesc("sim/hitches/
aerotow/tow/connected-to-ai-or-mp-callsign", VLProperty::STRING);
sIdPropertyDescMap[906] = VLMultiplayMgr:ropertyDesc("sim/hitches/
aerotow/tow/brake-force", VLProperty::FLOAT);
sIdPropertyDescMap[907] = VLMultiplayMgr:ropertyDesc("sim/hitches/
aerotow/tow/end-force-x", VLProperty::FLOAT);
sIdPropertyDescMap[908] = VLMultiplayMgr:ropertyDesc("sim/hitches/
aerotow/tow/end-force-y", VLProperty::FLOAT);
sIdPropertyDescMap[909] = VLMultiplayMgr:ropertyDesc("sim/hitches/
aerotow/tow/end-force-z", VLProperty::FLOAT);
sIdPropertyDescMap[930] = VLMultiplayMgr:ropertyDesc("sim/hitches/
aerotow/is-slave", VLProperty::BOOL);
sIdPropertyDescMap[931] = VLMultiplayMgr:ropertyDesc("sim/hitches/
aerotow/speed-in-tow-direction", VLProperty::FLOAT);
sIdPropertyDescMap[932] = VLMultiplayMgr:ropertyDesc("sim/hitches/
aerotow/open", VLProperty::BOOL);
sIdPropertyDescMap[933] = VLMultiplayMgr:ropertyDesc("sim/hitches/
aerotow/local-pos-x", VLProperty::FLOAT);
sIdPropertyDescMap[934] = VLMultiplayMgr:ropertyDesc("sim/hitches/
aerotow/local-pos-y", VLProperty::FLOAT);
sIdPropertyDescMap[935] = VLMultiplayMgr:ropertyDesc("sim/hitches/
aerotow/local-pos-z", VLProperty::FLOAT);
sIdPropertyDescMap[1001] = VLMultiplayMgr:ropertyDesc("controls/
flight/slats", VLProperty::FLOAT);
sIdPropertyDescMap[1002] = VLMultiplayMgr:ropertyDesc("controls/
flight/speedbrake", VLProperty::FLOAT);
sIdPropertyDescMap[1003] = VLMultiplayMgr:ropertyDesc("controls/
flight/spoilers", VLProperty::FLOAT);
sIdPropertyDescMap[1004] = VLMultiplayMgr:ropertyDesc("controls/
gear/gear-down", VLProperty::FLOAT);
sIdPropertyDescMap[1005] = VLMultiplayMgr:ropertyDesc("controls/
lighting/nav-lights", VLProperty::FLOAT);
sIdPropertyDescMap[1006] = VLMultiplayMgr:ropertyDesc("controls/
armament/station[0]/jettison-all", VLProperty::BOOL);
sIdPropertyDescMap[1100] = VLMultiplayMgr:ropertyDesc("sim/model/
variant", VLProperty::INT);
sIdPropertyDescMap[10001] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/transmission-freq-hz", VLProperty::STRING);
sIdPropertyDescMap[10002] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/chat", VLProperty::STRING);
sIdPropertyDescMap[10100] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/string[0]", VLProperty::STRING);
sIdPropertyDescMap[10101] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/string[1]", VLProperty::STRING);
sIdPropertyDescMap[10102] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/string[2]", VLProperty::STRING);
sIdPropertyDescMap[10103] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/string[3]", VLProperty::STRING);
sIdPropertyDescMap[10104] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/string[4]", VLProperty::STRING);
sIdPropertyDescMap[10105] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/string[5]", VLProperty::STRING);
sIdPropertyDescMap[10106] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/string[6]", VLProperty::STRING);
sIdPropertyDescMap[10107] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/string[7]", VLProperty::STRING);
sIdPropertyDescMap[10108] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/string[8]", VLProperty::STRING);
sIdPropertyDescMap[10109] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/string[9]", VLProperty::STRING);
sIdPropertyDescMap[10200] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/float[0]", VLProperty::FLOAT);
sIdPropertyDescMap[10201] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/float[1]", VLProperty::FLOAT);
sIdPropertyDescMap[10202] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/float[2]", VLProperty::FLOAT);
sIdPropertyDescMap[10203] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/float[3]", VLProperty::FLOAT);
sIdPropertyDescMap[10204] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/float[4]", VLProperty::FLOAT);
sIdPropertyDescMap[10205] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/float[5]", VLProperty::FLOAT);
sIdPropertyDescMap[10206] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/float[6]", VLProperty::FLOAT);
sIdPropertyDescMap[10207] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/float[7]", VLProperty::FLOAT);
sIdPropertyDescMap[10208] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/float[8]", VLProperty::FLOAT);
sIdPropertyDescMap[10209] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/float[9]", VLProperty::FLOAT);
sIdPropertyDescMap[10300] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/int[0]", VLProperty::INT);
sIdPropertyDescMap[10301] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/int[1]", VLProperty::INT);
sIdPropertyDescMap[10302] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/int[2]", VLProperty::INT);
sIdPropertyDescMap[10303] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/int[3]", VLProperty::INT);
sIdPropertyDescMap[10304] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/int[4]", VLProperty::INT);
sIdPropertyDescMap[10305] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/int[5]", VLProperty::INT);
sIdPropertyDescMap[10306] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/int[6]", VLProperty::INT);
sIdPropertyDescMap[10307] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/int[7]", VLProperty::INT);
sIdPropertyDescMap[10308] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/int[8]", VLProperty::INT);
sIdPropertyDescMap[10309] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/int[9]", VLProperty::INT);
}
VLAIManager::ModelPropertyDataMap
VLAIManager::sAircraftPropertyDataMap =
VLAIManager::ModelPropertyDataMap();
std::map<std::string,std::string>
VLAIManager::sAircraftModelNameMap =
std::map<std::string,std::string>();
std::vector<VLPropertyData>
VLAIManager::addProperties(const std::string& aircraft)
{
if (0 < sAircraftPropertyDataMap.count(aircraft))
return sAircraftPropertyDataMap[aircraft][1];
std::vector <VLPropertyData>* constantProperties;
std::vector <VLPropertyData>* varyingProperties;
VLPropertyData propertyData;
std::string modelName, id, value, cv;
//VLPropertyData* ptr;
//size_t pos = fileName.find('/');
//fileName = fileName.substr(pos + 1, fileName.find('/', pos+1) - pos
- 1) + ".txt";
std::ifstream myfile(("./data/" + aircraft + ".txt").data());
std::cout << __FILE__ << ":" << __LINE__ << " " << aircraft << "\n";
sAircraftPropertyDataMap[aircraft] = new std::vector
<VLPropertyData>[2];
constantProperties = &sAircraftPropertyDataMap[aircraft][0];
varyingProperties = &sAircraftPropertyDataMap[aircraft][1];
if (myfile.is_open())
{
myfile >> modelName;
sAircraftModelNameMap[aircraft] = modelName;
while (! myfile.eof() )
{
//ptr = new VLPropertyData;
myfile >> id >> value >> cv;
propertyData.id = atoi(id.data());
if (VLMultiplayMgr::sIdPropertyDescMap.count(propertyData.id) > 0)
{
propertyData.type =
VLMultiplayMgr::sIdPropertyDescMap[propertyData.id].type;;
// How we decode the remainder of the property depends on the type
switch (propertyData.type) {
case VLProperty::INT:
case VLProperty::BOOL:
case VLProperty::LONG:
propertyData.int_value = atoi(value.data());
//cout << pData->int_value << "\n";
break;
case VLProperty::FLOAT:
case VLProperty:OUBLE:
propertyData.float_value = atof(value.data());
//cout << pData->float_value << "\n";
break;
case VLProperty::STRING:
case VLProperty::UNSPECIFIED:
//propertyData.string_value = value;
//propertyData.string_value = (char*) (new
std::string(value.c_str()))->c_str();
int len;
len = value.length();
propertyData.string_value = new char[len + 1];
strcpy(propertyData.string_value, value.data());
propertyData.string_value[len] = '\0';
//std::cout << propertyData.string_value << "\n";
break;
default:
propertyData.float_value = atof(value.data());
std::cout << "Unknown Prop type " << propertyData.id << " " <<
propertyData.type << "\n";
break;
}
if (cv == "c")
constantProperties->push_back(propertyData);
else if (cv == "v")
varyingProperties->push_back(propertyData);
else
std::cout << "Property type c|v error\n";
}
else
{
// We failed to find the property. We'll try the next packet
immediately.
//cout << " Unknown\n";
}
myfile >> cv;
}
myfile.close();
}
else
std::cout << __FILE__ << ":" << __LINE__ << " "<< "Unable to open
file\n";
std::cout << __FILE__ << ":" << __LINE__ << " " << aircraft << "\n";
std::vector<VLPropertyData> var = sAircraftPropertyDataMap[aircraft]
[1];
std::cout << sAircraftPropertyDataMap.count(aircraft) << "\n";
return var;
}
VLAIManager::VLAIManager()
{
}
VLAIManager::~VLAIManager()
{
}
int
main()
{
VLAIManager* mgr = new VLAIManager;
VLMultiplayMgr::Init();
mgr->addProperties("bo105");
std::string name ("oktay");
std::cout << name.length()<< ":" << name.size() << "\n";
std::cout << "ok\n";
return 0;
}
//data file
Aircraft/bo105/Models/bo105.xml
10002 Hello c sim/multiplay/chat
10300 1 c sim/multiplay/generic/
int[0]
10001 118500000 c sim/multiplay/transmission-freq-hz
10100 Yellow_MedEvac c sim/multiplay/generic/string[0]
10101 red-cross c sim/multiplay/generic/string[1]
// output of program
new data
.../main.cpp:321 bo105
Hello is deleted
is deleted
*** glibc detected *** /home/mvms/workspace/reading/Debug/reading:
double free or corruption (fasttop): 0x0000000001f232a0 ***
======= Backtrace: =========
/lib64/libc.so.6[0x33c9a78158]
/lib64/libc.so.6(cfree+0x76)[0x33c9a7a796]
/home/mvms/workspace/reading/Debug/reading[0x408ed0]
/home/mvms/workspace/reading/Debug/reading[0x408ee7]
/home/mvms/workspace/reading/Debug/reading[0x408f04]
/home/mvms/workspace/reading/Debug/reading[0x408f36]
/home/mvms/workspace/reading/Debug/reading[0x40b666]
/home/mvms/workspace/reading/Debug/reading[0x40b73c]
/home/mvms/workspace/reading/Debug/reading[0x402137]
/home/mvms/workspace/reading/Debug/reading[0x4069d5]
/lib64/libc.so.6(__libc_start_main+0xfa)[0x33c9a1e32a]
/home/mvms/workspace/reading/Debug/reading(__gxx_personality_v0+0x91)
[0x4017e9]
======= Memory map: ========
00400000-00411000 r-xp 00000000 fd:00
295669 /home/mvms/workspace/reading/Debug/
reading
00610000-00611000 rw-p 00010000 fd:00
295669 /home/mvms/workspace/reading/Debug/
reading
01f1f000-01f40000 rw-p 01f1f000 00:00
0 [heap]
33c8800000-33c881d000 r-xp 00000000 fd:00
2179394 /lib64/ld-2.8.so
33c8a1c000-33c8a1d000 r--p 0001c000 fd:00
2179394 /lib64/ld-2.8.so
33c8a1d000-33c8a1e000 rw-p 0001d000 fd:00
2179394 /lib64/ld-2.8.so
33c9a00000-33c9b62000 r-xp 00000000 fd:00
2179395 /lib64/libc-2.8.so
33c9b62000-33c9d62000 ---p 00162000 fd:00
2179395 /lib64/libc-2.8.so
33c9d62000-33c9d66000 r--p 00162000 fd:00
2179395 /lib64/libc-2.8.so
33c9d66000-33c9d67000 rw-p 00166000 fd:00
2179395 /lib64/libc-2.8.so
33c9d67000-33c9d6c000 rw-p 33c9d67000 00:00 0
33c9e00000-33c9e84000 r-xp 00000000 fd:00
2179407 /lib64/libm-2.8.so
33c9e84000-33ca083000 ---p 00084000 fd:00
2179407 /lib64/libm-2.8.so
33ca083000-33ca084000 r--p 00083000 fd:00
2179407 /lib64/libm-2.8.so
33ca084000-33ca085000 rw-p 00084000 fd:00
2179407 /lib64/libm-2.8.so
33d0200000-33d0216000 r-xp 00000000 fd:00
2179408 /lib64/libgcc_s-4.3.0-20080428.so.1
33d0216000-33d0415000 ---p 00016000 fd:00
2179408 /lib64/libgcc_s-4.3.0-20080428.so.1
33d0415000-33d0416000 rw-p 00015000 fd:00
2179408 /lib64/libgcc_s-4.3.0-20080428.so.1
33d3e00000-33d3eee000 r-xp 00000000 fd:00
2602470 /usr/lib64/libstdc++.so.6.0.10
33d3eee000-33d40ee000 ---p 000ee000 fd:00
2602470 /usr/lib64/libstdc++.so.6.0.10
33d40ee000-33d40f5000 r--p 000ee000 fd:00
2602470 /usr/lib64/libstdc++.so.6.0.10
33d40f5000-33d40f7000 rw-p 000f5000 fd:00
2602470 /usr/lib64/libstdc++.so.6.0.10
33d40f7000-33d410a000 rw-p 33d40f7000 00:00 0
7f9f40000000-7f9f40021000 rw-p 7f9f40000000 00:00 0
7f9f40021000-7f9f44000000 ---p 7f9f40021000 00:00 0
7f9f449f6000-7f9f449f9000 rw-p 7f9f449f6000 00:00 0
7f9f44a14000-7f9f44a17000 rw-p 7f9f44a14000 00:00 0
7fff4ca01000-7fff4ca16000 rw-p 7ffffffea000 00:00
0 [stack]
7fff4cbfe000-7fff4cc00000 r-xp 7fff4cbfe000 00:00
0 [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00
0 [vsyscall]
I have a problem when inserting an element to a vector. All I want is
reading some data from a file and putting them into a vector. But the
program is crashing after pushing a data which has string value. I
really do not understand why push_back() function is trying to remove
previously inserted data.
Thanks for any help
yatko
// program
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cstdlib>
#include <string.h>
class VLProperty
{
public:
enum Aircraft{
BO105,
F16
};
enum Type{
INT,
BOOL,
LONG,
FLOAT,
DOUBLE,
STRING,
UNSPECIFIED
};
};
struct VLPropertyData {
unsigned id;
// While the type isn't transmitted, it is needed for the destructor
VLProperty::Type type;
union{
int int_value;
float float_value;
char* string_value;
};
//std::string string_value;
VLPropertyData()
{
std::cout << "new data\n";
}
~VLPropertyData() {
if ((type == VLProperty::STRING) || (type ==
VLProperty::UNSPECIFIED))
{
std::cout << string_value << " is deleted" << std::endl;
delete [] string_value;
}
}
};
class VLAIMultiplayer;
class VLAIManager
{
public:
static std::string sAircraftIdList[];
static std::map<std::string,std::string> sAircraftModelNameMap;
/// maps from the aircraft string to the VLPropertyData vector
typedef std::map< std::string, std::vector <VLPropertyData>* >
ModelPropertyDataMap;
//static ModelPropertyDataMap sModelPropertyDataMap;
static ModelPropertyDataMap sAircraftPropertyDataMap;
VLAIManager();
~VLAIManager();
VLAIMultiplayer* addMultiplayer(const std::string& callsign, const
std::string& aircraft);
std::vector <VLPropertyData>
addProperties(const std::string& aircraft);
private:
/// maps from the callsign string to the VLAIMultiplayer
typedef std::map<std::string, VLAIMultiplayer* > MultiPlayerMap;
MultiPlayerMap mMultiPlayerMap;
};
struct VLExternalMotionInfo;
class VLMultiplayMgr
{
public:
struct PropertyDesc{
PropertyDesc()
{};
PropertyDesc(const char* name, VLProperty::Type type)
{
this->name = name;
this->type = type;
};
~PropertyDesc()
{};
const char* name;
VLProperty::Type type;
};
typedef std::map<unsigned int, PropertyDesc> IdPropertyDescMap;
static IdPropertyDescMap sIdPropertyDescMap;
static void Init();
private:
/// maps from the callsign string to the FGAIMultiplayer
typedef std::map<std::string, VLAIMultiplayer* > MultiPlayerMap;
MultiPlayerMap mMultiPlayerMap;
};
std::string VLAIManager::sAircraftIdList [] = {
"",
"t38",
"bo105",
"F16",
"b1900d"
};
VLMultiplayMgr::IdPropertyDescMap VLMultiplayMgr::sIdPropertyDescMap =
VLMultiplayMgr::IdPropertyDescMap();
void
VLMultiplayMgr::Init()
{
sIdPropertyDescMap[100] = VLMultiplayMgr:ropertyDesc("surface-
positions/left-aileron-pos-norm", VLProperty::FLOAT);
sIdPropertyDescMap[101] = VLMultiplayMgr:ropertyDesc("surface-
positions/right-aileron-pos-norm", VLProperty::FLOAT);
sIdPropertyDescMap[102] = VLMultiplayMgr:ropertyDesc("surface-
positions/elevator-pos-norm", VLProperty::FLOAT);
sIdPropertyDescMap[103] = VLMultiplayMgr:ropertyDesc("surface-
positions/rudder-pos-norm", VLProperty::FLOAT);
sIdPropertyDescMap[104] = VLMultiplayMgr:ropertyDesc("surface-
positions/flap-pos-norm", VLProperty::FLOAT);
sIdPropertyDescMap[105] = VLMultiplayMgr:ropertyDesc("surface-
positions/speedbrake-pos-norm", VLProperty::FLOAT);
sIdPropertyDescMap[106] = VLMultiplayMgr:ropertyDesc("gear/tailhook/
position-norm", VLProperty::FLOAT);
sIdPropertyDescMap[107] = VLMultiplayMgr:ropertyDesc("gear/
launchbar/position-norm", VLProperty::FLOAT);
sIdPropertyDescMap[108] = VLMultiplayMgr:ropertyDesc("gear/
launchbar/state", VLProperty::STRING);
sIdPropertyDescMap[109] = VLMultiplayMgr:ropertyDesc("gear/
launchbar/holdback-position-norm", VLProperty::FLOAT);
sIdPropertyDescMap[110] = VLMultiplayMgr:ropertyDesc("canopy/
position-norm", VLProperty::FLOAT);
sIdPropertyDescMap[200] = VLMultiplayMgr:ropertyDesc("gear/gear[0]/
compression-norm", VLProperty::FLOAT);
sIdPropertyDescMap[201] = VLMultiplayMgr:ropertyDesc("gear/gear[0]/
position-norm", VLProperty::FLOAT);
sIdPropertyDescMap[210] = VLMultiplayMgr:ropertyDesc("gear/gear[1]/
compression-norm", VLProperty::FLOAT);
sIdPropertyDescMap[211] = VLMultiplayMgr:ropertyDesc("gear/gear[1]/
position-norm", VLProperty::FLOAT);
sIdPropertyDescMap[220] = VLMultiplayMgr:ropertyDesc("gear/gear[2]/
compression-norm", VLProperty::FLOAT);
sIdPropertyDescMap[221] = VLMultiplayMgr:ropertyDesc("gear/gear[2]/
position-norm", VLProperty::FLOAT);
sIdPropertyDescMap[230] = VLMultiplayMgr:ropertyDesc("gear/gear[3]/
compression-norm", VLProperty::FLOAT);
sIdPropertyDescMap[231] = VLMultiplayMgr:ropertyDesc("gear/gear[3]/
position-norm", VLProperty::FLOAT);
sIdPropertyDescMap[240] = VLMultiplayMgr:ropertyDesc("gear/gear[4]/
compression-norm", VLProperty::FLOAT);
sIdPropertyDescMap[241] = VLMultiplayMgr:ropertyDesc("gear/gear[4]/
position-norm", VLProperty::FLOAT);
sIdPropertyDescMap[300] = VLMultiplayMgr:ropertyDesc("engines/
engine[0]/n1", VLProperty::FLOAT);
sIdPropertyDescMap[301] = VLMultiplayMgr:ropertyDesc("engines/
engine[0]/n2", VLProperty::FLOAT);
sIdPropertyDescMap[302] = VLMultiplayMgr:ropertyDesc("engines/
engine[0]/rpm", VLProperty::FLOAT);
sIdPropertyDescMap[310] = VLMultiplayMgr:ropertyDesc("engines/
engine[1]/n1", VLProperty::FLOAT);
sIdPropertyDescMap[311] = VLMultiplayMgr:ropertyDesc("engines/
engine[1]/n2", VLProperty::FLOAT);
sIdPropertyDescMap[312] = VLMultiplayMgr:ropertyDesc("engines/
engine[1]/rpm", VLProperty::FLOAT);
sIdPropertyDescMap[320] = VLMultiplayMgr:ropertyDesc("engines/
engine[2]/n1", VLProperty::FLOAT);
sIdPropertyDescMap[321] = VLMultiplayMgr:ropertyDesc("engines/
engine[2]/n2", VLProperty::FLOAT);
sIdPropertyDescMap[322] = VLMultiplayMgr:ropertyDesc("engines/
engine[2]/rpm", VLProperty::FLOAT);
sIdPropertyDescMap[330] = VLMultiplayMgr:ropertyDesc("engines/
engine[3]/n1", VLProperty::FLOAT);
sIdPropertyDescMap[331] = VLMultiplayMgr:ropertyDesc("engines/
engine[3]/n2", VLProperty::FLOAT);
sIdPropertyDescMap[332] = VLMultiplayMgr:ropertyDesc("engines/
engine[3]/rpm", VLProperty::FLOAT);
sIdPropertyDescMap[340] = VLMultiplayMgr:ropertyDesc("engines/
engine[4]/n1", VLProperty::FLOAT);
sIdPropertyDescMap[341] = VLMultiplayMgr:ropertyDesc("engines/
engine[4]/n2", VLProperty::FLOAT);
sIdPropertyDescMap[342] = VLMultiplayMgr:ropertyDesc("engines/
engine[4]/rpm", VLProperty::FLOAT);
sIdPropertyDescMap[350] = VLMultiplayMgr:ropertyDesc("engines/
engine[5]/n1", VLProperty::FLOAT);
sIdPropertyDescMap[351] = VLMultiplayMgr:ropertyDesc("engines/
engine[5]/n2", VLProperty::FLOAT);
sIdPropertyDescMap[352] = VLMultiplayMgr:ropertyDesc("engines/
engine[5]/rpm", VLProperty::FLOAT);
sIdPropertyDescMap[360] = VLMultiplayMgr:ropertyDesc("engines/
engine[6]/n1", VLProperty::FLOAT);
sIdPropertyDescMap[361] = VLMultiplayMgr:ropertyDesc("engines/
engine[6]/n2", VLProperty::FLOAT);
sIdPropertyDescMap[362] = VLMultiplayMgr:ropertyDesc("engines/
engine[6]/rpm", VLProperty::FLOAT);
sIdPropertyDescMap[370] = VLMultiplayMgr:ropertyDesc("engines/
engine[7]/n1", VLProperty::FLOAT);
sIdPropertyDescMap[371] = VLMultiplayMgr:ropertyDesc("engines/
engine[7]/n2", VLProperty::FLOAT);
sIdPropertyDescMap[372] = VLMultiplayMgr:ropertyDesc("engines/
engine[7]/rpm", VLProperty::FLOAT);
sIdPropertyDescMap[380] = VLMultiplayMgr:ropertyDesc("engines/
engine[8]/n1", VLProperty::FLOAT);
sIdPropertyDescMap[381] = VLMultiplayMgr:ropertyDesc("engines/
engine[8]/n2", VLProperty::FLOAT);
sIdPropertyDescMap[382] = VLMultiplayMgr:ropertyDesc("engines/
engine[8]/rpm", VLProperty::FLOAT);
sIdPropertyDescMap[390] = VLMultiplayMgr:ropertyDesc("engines/
engine[9]/n1", VLProperty::FLOAT);
sIdPropertyDescMap[391] = VLMultiplayMgr:ropertyDesc("engines/
engine[9]/n2", VLProperty::FLOAT);
sIdPropertyDescMap[392] = VLMultiplayMgr:ropertyDesc("engines/
engine[9]/rpm", VLProperty::FLOAT);
sIdPropertyDescMap[800] = VLMultiplayMgr:ropertyDesc("rotors/main/
rpm", VLProperty::FLOAT);
sIdPropertyDescMap[801] = VLMultiplayMgr:ropertyDesc("rotors/tail/
rpm", VLProperty::FLOAT);
sIdPropertyDescMap[810] = VLMultiplayMgr:ropertyDesc("rotors/main/
blade[0]/position-deg", VLProperty::FLOAT);
sIdPropertyDescMap[811] = VLMultiplayMgr:ropertyDesc("rotors/main/
blade[1]/position-deg", VLProperty::FLOAT);
sIdPropertyDescMap[812] = VLMultiplayMgr:ropertyDesc("rotors/main/
blade[2]/position-deg", VLProperty::FLOAT);
sIdPropertyDescMap[813] = VLMultiplayMgr:ropertyDesc("rotors/main/
blade[3]/position-deg", VLProperty::FLOAT);
sIdPropertyDescMap[820] = VLMultiplayMgr:ropertyDesc("rotors/main/
blade[0]/flap-deg", VLProperty::FLOAT);
sIdPropertyDescMap[821] = VLMultiplayMgr:ropertyDesc("rotors/main/
blade[1]/flap-deg", VLProperty::FLOAT);
sIdPropertyDescMap[822] = VLMultiplayMgr:ropertyDesc("rotors/main/
blade[2]/flap-deg", VLProperty::FLOAT);
sIdPropertyDescMap[823] = VLMultiplayMgr:ropertyDesc("rotors/main/
blade[3]/flap-deg", VLProperty::FLOAT);
sIdPropertyDescMap[830] = VLMultiplayMgr:ropertyDesc("rotors/tail/
blade[0]/position-deg", VLProperty::FLOAT);
sIdPropertyDescMap[831] = VLMultiplayMgr:ropertyDesc("rotors/tail/
blade[1]/position-deg", VLProperty::FLOAT);
sIdPropertyDescMap[900] = VLMultiplayMgr:ropertyDesc("sim/hitches/
aerotow/tow/length", VLProperty::FLOAT);
sIdPropertyDescMap[901] = VLMultiplayMgr:ropertyDesc("sim/hitches/
aerotow/tow/elastic-constant", VLProperty::FLOAT);
sIdPropertyDescMap[902] = VLMultiplayMgr:ropertyDesc("sim/hitches/
aerotow/tow/weight-per-m-kg-m", VLProperty::FLOAT);
sIdPropertyDescMap[903] = VLMultiplayMgr:ropertyDesc("sim/hitches/
aerotow/tow/dist", VLProperty::FLOAT);
sIdPropertyDescMap[904] = VLMultiplayMgr:ropertyDesc("sim/hitches/
aerotow/tow/connected-to-property-node", VLProperty::BOOL);
sIdPropertyDescMap[905] = VLMultiplayMgr:ropertyDesc("sim/hitches/
aerotow/tow/connected-to-ai-or-mp-callsign", VLProperty::STRING);
sIdPropertyDescMap[906] = VLMultiplayMgr:ropertyDesc("sim/hitches/
aerotow/tow/brake-force", VLProperty::FLOAT);
sIdPropertyDescMap[907] = VLMultiplayMgr:ropertyDesc("sim/hitches/
aerotow/tow/end-force-x", VLProperty::FLOAT);
sIdPropertyDescMap[908] = VLMultiplayMgr:ropertyDesc("sim/hitches/
aerotow/tow/end-force-y", VLProperty::FLOAT);
sIdPropertyDescMap[909] = VLMultiplayMgr:ropertyDesc("sim/hitches/
aerotow/tow/end-force-z", VLProperty::FLOAT);
sIdPropertyDescMap[930] = VLMultiplayMgr:ropertyDesc("sim/hitches/
aerotow/is-slave", VLProperty::BOOL);
sIdPropertyDescMap[931] = VLMultiplayMgr:ropertyDesc("sim/hitches/
aerotow/speed-in-tow-direction", VLProperty::FLOAT);
sIdPropertyDescMap[932] = VLMultiplayMgr:ropertyDesc("sim/hitches/
aerotow/open", VLProperty::BOOL);
sIdPropertyDescMap[933] = VLMultiplayMgr:ropertyDesc("sim/hitches/
aerotow/local-pos-x", VLProperty::FLOAT);
sIdPropertyDescMap[934] = VLMultiplayMgr:ropertyDesc("sim/hitches/
aerotow/local-pos-y", VLProperty::FLOAT);
sIdPropertyDescMap[935] = VLMultiplayMgr:ropertyDesc("sim/hitches/
aerotow/local-pos-z", VLProperty::FLOAT);
sIdPropertyDescMap[1001] = VLMultiplayMgr:ropertyDesc("controls/
flight/slats", VLProperty::FLOAT);
sIdPropertyDescMap[1002] = VLMultiplayMgr:ropertyDesc("controls/
flight/speedbrake", VLProperty::FLOAT);
sIdPropertyDescMap[1003] = VLMultiplayMgr:ropertyDesc("controls/
flight/spoilers", VLProperty::FLOAT);
sIdPropertyDescMap[1004] = VLMultiplayMgr:ropertyDesc("controls/
gear/gear-down", VLProperty::FLOAT);
sIdPropertyDescMap[1005] = VLMultiplayMgr:ropertyDesc("controls/
lighting/nav-lights", VLProperty::FLOAT);
sIdPropertyDescMap[1006] = VLMultiplayMgr:ropertyDesc("controls/
armament/station[0]/jettison-all", VLProperty::BOOL);
sIdPropertyDescMap[1100] = VLMultiplayMgr:ropertyDesc("sim/model/
variant", VLProperty::INT);
sIdPropertyDescMap[10001] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/transmission-freq-hz", VLProperty::STRING);
sIdPropertyDescMap[10002] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/chat", VLProperty::STRING);
sIdPropertyDescMap[10100] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/string[0]", VLProperty::STRING);
sIdPropertyDescMap[10101] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/string[1]", VLProperty::STRING);
sIdPropertyDescMap[10102] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/string[2]", VLProperty::STRING);
sIdPropertyDescMap[10103] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/string[3]", VLProperty::STRING);
sIdPropertyDescMap[10104] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/string[4]", VLProperty::STRING);
sIdPropertyDescMap[10105] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/string[5]", VLProperty::STRING);
sIdPropertyDescMap[10106] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/string[6]", VLProperty::STRING);
sIdPropertyDescMap[10107] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/string[7]", VLProperty::STRING);
sIdPropertyDescMap[10108] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/string[8]", VLProperty::STRING);
sIdPropertyDescMap[10109] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/string[9]", VLProperty::STRING);
sIdPropertyDescMap[10200] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/float[0]", VLProperty::FLOAT);
sIdPropertyDescMap[10201] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/float[1]", VLProperty::FLOAT);
sIdPropertyDescMap[10202] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/float[2]", VLProperty::FLOAT);
sIdPropertyDescMap[10203] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/float[3]", VLProperty::FLOAT);
sIdPropertyDescMap[10204] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/float[4]", VLProperty::FLOAT);
sIdPropertyDescMap[10205] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/float[5]", VLProperty::FLOAT);
sIdPropertyDescMap[10206] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/float[6]", VLProperty::FLOAT);
sIdPropertyDescMap[10207] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/float[7]", VLProperty::FLOAT);
sIdPropertyDescMap[10208] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/float[8]", VLProperty::FLOAT);
sIdPropertyDescMap[10209] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/float[9]", VLProperty::FLOAT);
sIdPropertyDescMap[10300] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/int[0]", VLProperty::INT);
sIdPropertyDescMap[10301] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/int[1]", VLProperty::INT);
sIdPropertyDescMap[10302] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/int[2]", VLProperty::INT);
sIdPropertyDescMap[10303] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/int[3]", VLProperty::INT);
sIdPropertyDescMap[10304] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/int[4]", VLProperty::INT);
sIdPropertyDescMap[10305] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/int[5]", VLProperty::INT);
sIdPropertyDescMap[10306] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/int[6]", VLProperty::INT);
sIdPropertyDescMap[10307] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/int[7]", VLProperty::INT);
sIdPropertyDescMap[10308] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/int[8]", VLProperty::INT);
sIdPropertyDescMap[10309] = VLMultiplayMgr:ropertyDesc("sim/
multiplay/generic/int[9]", VLProperty::INT);
}
VLAIManager::ModelPropertyDataMap
VLAIManager::sAircraftPropertyDataMap =
VLAIManager::ModelPropertyDataMap();
std::map<std::string,std::string>
VLAIManager::sAircraftModelNameMap =
std::map<std::string,std::string>();
std::vector<VLPropertyData>
VLAIManager::addProperties(const std::string& aircraft)
{
if (0 < sAircraftPropertyDataMap.count(aircraft))
return sAircraftPropertyDataMap[aircraft][1];
std::vector <VLPropertyData>* constantProperties;
std::vector <VLPropertyData>* varyingProperties;
VLPropertyData propertyData;
std::string modelName, id, value, cv;
//VLPropertyData* ptr;
//size_t pos = fileName.find('/');
//fileName = fileName.substr(pos + 1, fileName.find('/', pos+1) - pos
- 1) + ".txt";
std::ifstream myfile(("./data/" + aircraft + ".txt").data());
std::cout << __FILE__ << ":" << __LINE__ << " " << aircraft << "\n";
sAircraftPropertyDataMap[aircraft] = new std::vector
<VLPropertyData>[2];
constantProperties = &sAircraftPropertyDataMap[aircraft][0];
varyingProperties = &sAircraftPropertyDataMap[aircraft][1];
if (myfile.is_open())
{
myfile >> modelName;
sAircraftModelNameMap[aircraft] = modelName;
while (! myfile.eof() )
{
//ptr = new VLPropertyData;
myfile >> id >> value >> cv;
propertyData.id = atoi(id.data());
if (VLMultiplayMgr::sIdPropertyDescMap.count(propertyData.id) > 0)
{
propertyData.type =
VLMultiplayMgr::sIdPropertyDescMap[propertyData.id].type;;
// How we decode the remainder of the property depends on the type
switch (propertyData.type) {
case VLProperty::INT:
case VLProperty::BOOL:
case VLProperty::LONG:
propertyData.int_value = atoi(value.data());
//cout << pData->int_value << "\n";
break;
case VLProperty::FLOAT:
case VLProperty:OUBLE:
propertyData.float_value = atof(value.data());
//cout << pData->float_value << "\n";
break;
case VLProperty::STRING:
case VLProperty::UNSPECIFIED:
//propertyData.string_value = value;
//propertyData.string_value = (char*) (new
std::string(value.c_str()))->c_str();
int len;
len = value.length();
propertyData.string_value = new char[len + 1];
strcpy(propertyData.string_value, value.data());
propertyData.string_value[len] = '\0';
//std::cout << propertyData.string_value << "\n";
break;
default:
propertyData.float_value = atof(value.data());
std::cout << "Unknown Prop type " << propertyData.id << " " <<
propertyData.type << "\n";
break;
}
if (cv == "c")
constantProperties->push_back(propertyData);
else if (cv == "v")
varyingProperties->push_back(propertyData);
else
std::cout << "Property type c|v error\n";
}
else
{
// We failed to find the property. We'll try the next packet
immediately.
//cout << " Unknown\n";
}
myfile >> cv;
}
myfile.close();
}
else
std::cout << __FILE__ << ":" << __LINE__ << " "<< "Unable to open
file\n";
std::cout << __FILE__ << ":" << __LINE__ << " " << aircraft << "\n";
std::vector<VLPropertyData> var = sAircraftPropertyDataMap[aircraft]
[1];
std::cout << sAircraftPropertyDataMap.count(aircraft) << "\n";
return var;
}
VLAIManager::VLAIManager()
{
}
VLAIManager::~VLAIManager()
{
}
int
main()
{
VLAIManager* mgr = new VLAIManager;
VLMultiplayMgr::Init();
mgr->addProperties("bo105");
std::string name ("oktay");
std::cout << name.length()<< ":" << name.size() << "\n";
std::cout << "ok\n";
return 0;
}
//data file
Aircraft/bo105/Models/bo105.xml
10002 Hello c sim/multiplay/chat
10300 1 c sim/multiplay/generic/
int[0]
10001 118500000 c sim/multiplay/transmission-freq-hz
10100 Yellow_MedEvac c sim/multiplay/generic/string[0]
10101 red-cross c sim/multiplay/generic/string[1]
// output of program
new data
.../main.cpp:321 bo105
Hello is deleted
is deleted
*** glibc detected *** /home/mvms/workspace/reading/Debug/reading:
double free or corruption (fasttop): 0x0000000001f232a0 ***
======= Backtrace: =========
/lib64/libc.so.6[0x33c9a78158]
/lib64/libc.so.6(cfree+0x76)[0x33c9a7a796]
/home/mvms/workspace/reading/Debug/reading[0x408ed0]
/home/mvms/workspace/reading/Debug/reading[0x408ee7]
/home/mvms/workspace/reading/Debug/reading[0x408f04]
/home/mvms/workspace/reading/Debug/reading[0x408f36]
/home/mvms/workspace/reading/Debug/reading[0x40b666]
/home/mvms/workspace/reading/Debug/reading[0x40b73c]
/home/mvms/workspace/reading/Debug/reading[0x402137]
/home/mvms/workspace/reading/Debug/reading[0x4069d5]
/lib64/libc.so.6(__libc_start_main+0xfa)[0x33c9a1e32a]
/home/mvms/workspace/reading/Debug/reading(__gxx_personality_v0+0x91)
[0x4017e9]
======= Memory map: ========
00400000-00411000 r-xp 00000000 fd:00
295669 /home/mvms/workspace/reading/Debug/
reading
00610000-00611000 rw-p 00010000 fd:00
295669 /home/mvms/workspace/reading/Debug/
reading
01f1f000-01f40000 rw-p 01f1f000 00:00
0 [heap]
33c8800000-33c881d000 r-xp 00000000 fd:00
2179394 /lib64/ld-2.8.so
33c8a1c000-33c8a1d000 r--p 0001c000 fd:00
2179394 /lib64/ld-2.8.so
33c8a1d000-33c8a1e000 rw-p 0001d000 fd:00
2179394 /lib64/ld-2.8.so
33c9a00000-33c9b62000 r-xp 00000000 fd:00
2179395 /lib64/libc-2.8.so
33c9b62000-33c9d62000 ---p 00162000 fd:00
2179395 /lib64/libc-2.8.so
33c9d62000-33c9d66000 r--p 00162000 fd:00
2179395 /lib64/libc-2.8.so
33c9d66000-33c9d67000 rw-p 00166000 fd:00
2179395 /lib64/libc-2.8.so
33c9d67000-33c9d6c000 rw-p 33c9d67000 00:00 0
33c9e00000-33c9e84000 r-xp 00000000 fd:00
2179407 /lib64/libm-2.8.so
33c9e84000-33ca083000 ---p 00084000 fd:00
2179407 /lib64/libm-2.8.so
33ca083000-33ca084000 r--p 00083000 fd:00
2179407 /lib64/libm-2.8.so
33ca084000-33ca085000 rw-p 00084000 fd:00
2179407 /lib64/libm-2.8.so
33d0200000-33d0216000 r-xp 00000000 fd:00
2179408 /lib64/libgcc_s-4.3.0-20080428.so.1
33d0216000-33d0415000 ---p 00016000 fd:00
2179408 /lib64/libgcc_s-4.3.0-20080428.so.1
33d0415000-33d0416000 rw-p 00015000 fd:00
2179408 /lib64/libgcc_s-4.3.0-20080428.so.1
33d3e00000-33d3eee000 r-xp 00000000 fd:00
2602470 /usr/lib64/libstdc++.so.6.0.10
33d3eee000-33d40ee000 ---p 000ee000 fd:00
2602470 /usr/lib64/libstdc++.so.6.0.10
33d40ee000-33d40f5000 r--p 000ee000 fd:00
2602470 /usr/lib64/libstdc++.so.6.0.10
33d40f5000-33d40f7000 rw-p 000f5000 fd:00
2602470 /usr/lib64/libstdc++.so.6.0.10
33d40f7000-33d410a000 rw-p 33d40f7000 00:00 0
7f9f40000000-7f9f40021000 rw-p 7f9f40000000 00:00 0
7f9f40021000-7f9f44000000 ---p 7f9f40021000 00:00 0
7f9f449f6000-7f9f449f9000 rw-p 7f9f449f6000 00:00 0
7f9f44a14000-7f9f44a17000 rw-p 7f9f44a14000 00:00 0
7fff4ca01000-7fff4ca16000 rw-p 7ffffffea000 00:00
0 [stack]
7fff4cbfe000-7fff4cc00000 r-xp 7fff4cbfe000 00:00
0 [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00
0 [vsyscall]