how to emit or write a map of maps into a yaml file ?

So I have couple of virtual goggle .. each one of them has different calibration parameters. I decided to save these parameters into a yaml file (as a configuration file) .. each goggle has its own serial/identification number ... and based on this number, I select which one to use. If there is no pre-saved information for the goggle. I calibrate it and I add these parameters into the file
So right now I am trying to write to a yaml file which looks like this:

1
2
3
4
5
6
7
8
9
 Headset:
  IdentificationNumber: b630cc42-9a03-42da-a039-0e023cf5b090
  GyroOffset:
    GyroX:
      Value: -0.013776619
    GyroY:
      Value: -0.016475508
    GyroZ:
      Value: -0.0114268782



and this is what I get actually:

1
2
3
4
5
6
7
8
9
Headset2:
  IdentificationNumber: b630cc42-9a03-42da-a039-0e023cf5b090
? GyroOffset:
    GyroX:
      Value: -0.013776619
  ? GyroY:
      Value: -0.016475508
  : GyroZ:
      Value: -0.0114268782


I do not figure out what I am doing wrong ! .. here is my function which writes to the yaml file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
void ParseInputDeviceYaml::addCalibrationToConfigFile(const char* identificationNumber, const float* in)
{
    try {
        std::ofstream updatedFile;
        updatedFile.open(m_filename.toStdString(), std::ios::app);

        std::map<std::string, std::string>                  IDNumber;
        std::map<std::string, std::map<std::string, float>> gyroXOffset;
        std::map<std::string, std::map<std::string, float>> gyroYOffset;
        std::map<std::string, std::map<std::string, float>> gyroZOffset;

        IDNumber["IdentificationNumber"] = identificationNumber;

        gyroXOffset["GyroX"]["Value"] = *in;
        gyroYOffset["GyroY"]["Value"] = *(in + 1);
        gyroZOffset["GyroZ"]["Value"] = *(in + 2);

        YAML::Emitter newNode;


        newNode << YAML::BeginMap;
        newNode << YAML::Key << "Headset2";
        newNode << YAML::Value << YAML::BeginMap << YAML::Key << "IdentificationNumber" << YAML::Value << identificationNumber << YAML::EndMap;
        newNode << YAML::BeginMap << YAML::Key << "GyroOffset" << YAML::Value << gyroXOffset << gyroYOffset << gyroZOffset << YAML::EndMap;
        newNode << YAML::EndMap;

        updatedFile << newNode.c_str() << "\n";

        updatedFile.close();
    } catch (std::exception& e) {
        LOG4CPLUS_FATAL(m_logger, e.what());
        throw std::runtime_error(QObject::tr("Writing gyroscope offsets ").toStdString());
    }
Last edited on
I can't test, but what do you get with:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
std::map<std::string, std::map<std::string, float>> gyro;
gyro["GyroX"]["Value"] = *in;
gyro["GyroY"]["Value"] = *(in + 1);
gyro["GyroZ"]["Value"] = *(in + 2);

YAML::Emitter newNode;
newNode << YAML::BeginMap;
newNode << YAML::Key << "Headset2";
newNode << YAML::Value;
newNode   << YAML::BeginMap
newNode   << YAML::Key << "IdentificationNumber" << YAML::Value << identificationNumber;
newNode   << YAML::Key << "GyroOffset" << YAML::Value << gyro;
newNode   << YAML::EndMap;
newNode << YAML::EndMap;

That did it , thanks
Topic archived. No new replies allowed.