From dfe55cf2171b851832d4c37f1c2cdd382c2beff8 Mon Sep 17 00:00:00 2001 From: darren Date: Wed, 29 May 2019 14:06:19 -0700 Subject: [PATCH] changes for latest yaml-cpp and CPP 11 --- CMakeLists.txt | 3 ++- examples/pinproctest/pinproctest.cpp | 9 ++------- examples/pinproctest/switches.cpp | 24 +++++++++++------------- 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0853ac4..54213b8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,12 +13,13 @@ if(POLICY CMP0015) cmake_policy(SET CMP0015 OLD) endif() - ### ### Project settings ### project(PINPROC) +set (CMAKE_CXX_STANDARD 11) + set(PINPROC_VERSION_MAJOR "2") set(PINPROC_VERSION_MINOR "0") set(PINPROC_VERSION "${PINPROC_VERSION_MAJOR}.${PINPROC_VERSION_MINOR}") diff --git a/examples/pinproctest/pinproctest.cpp b/examples/pinproctest/pinproctest.cpp index 1729a57..7800930 100644 --- a/examples/pinproctest/pinproctest.cpp +++ b/examples/pinproctest/pinproctest.cpp @@ -46,12 +46,8 @@ PRResult LoadConfiguration(YAML::Node& yamlDoc, const char *yamlFilePath) fprintf(stderr, "YAML file not found: %s\n", yamlFilePath); return kPRFailure; } - YAML::Parser parser(fin); - while(parser) - { - parser.GetNextDocument(yamlDoc); - } + yamlDoc = YAML::Load(fin); } // catch (YAML::ParserException& ex) // { @@ -341,8 +337,7 @@ int main(int argc, const char **argv) return 1; } - std::string machineTypeString; - yamlDoc["PRGame"]["machineType"] >> machineTypeString; + std::string machineTypeString = yamlDoc["PRGame"]["machineType"].as(); if (machineTypeString == "wpc") machineType = kPRMachineWPC; else if (machineTypeString == "wpc95") diff --git a/examples/pinproctest/switches.cpp b/examples/pinproctest/switches.cpp index 5b19132..491def6 100644 --- a/examples/pinproctest/switches.cpp +++ b/examples/pinproctest/switches.cpp @@ -142,36 +142,34 @@ void ConfigureSwitchRules(PRHandle proc, YAML::Node& yamlDoc) // WPC Flippers std::string numStr; const YAML::Node& flippers = yamlDoc[kFlippersSection]; - for (YAML::Iterator flippersIt = flippers.begin(); flippersIt != flippers.end(); ++flippersIt) + for (YAML::const_iterator flippersIt = flippers.begin(); flippersIt != flippers.end(); ++flippersIt) { int swNum, coilMain, coilHold; - std::string flipperName; - *flippersIt >> flipperName; + std::string flipperName = flippersIt->as(); if (machineType == kPRMachineWPC) { - yamlDoc[kSwitchesSection][flipperName][kNumberField] >> numStr; swNum = PRDecode(machineType, numStr.c_str()); - yamlDoc[kCoilsSection][flipperName + "Main"][kNumberField] >> numStr; coilMain = PRDecode(machineType, numStr.c_str()); - yamlDoc[kCoilsSection][flipperName + "Hold"][kNumberField] >> numStr; coilHold = PRDecode(machineType, numStr.c_str()); + numStr = yamlDoc[kSwitchesSection][flipperName][kNumberField].as(); swNum = PRDecode(machineType, numStr.c_str()); + numStr = yamlDoc[kCoilsSection][flipperName + "Main"][kNumberField].as(); coilMain = PRDecode(machineType, numStr.c_str()); + numStr = yamlDoc[kCoilsSection][flipperName + "Hold"][kNumberField].as(); coilHold = PRDecode(machineType, numStr.c_str()); ConfigureWPCFlipperSwitchRule (proc, swNum, coilMain, coilHold, kFlipperPulseTime); } else if (machineType == kPRMachineSternWhitestar || machineType == kPRMachineSternSAM) { printf("hi\n"); - yamlDoc[kSwitchesSection][flipperName][kNumberField] >> numStr; swNum = PRDecode(machineType, numStr.c_str()); - yamlDoc[kCoilsSection][flipperName + "Main"][kNumberField] >> numStr; coilMain = PRDecode(machineType, numStr.c_str()); + numStr = yamlDoc[kSwitchesSection][flipperName][kNumberField].as(); swNum = PRDecode(machineType, numStr.c_str()); + numStr = yamlDoc[kCoilsSection][flipperName + "Main"][kNumberField].as(); coilMain = PRDecode(machineType, numStr.c_str()); ConfigureSternFlipperSwitchRule (proc, swNum, coilMain, kFlipperPulseTime, kFlipperPatterOnTime, kFlipperPatterOffTime); } } const YAML::Node& bumpers = yamlDoc[kBumpersSection]; - for (YAML::Iterator bumpersIt = bumpers.begin(); bumpersIt != bumpers.end(); ++bumpersIt) + for (YAML::const_iterator bumpersIt = bumpers.begin(); bumpersIt != bumpers.end(); ++bumpersIt) { int swNum, coilNum; // WPC Slingshots - std::string bumperName; - *bumpersIt >> bumperName; - yamlDoc[kSwitchesSection][bumperName][kNumberField] >> numStr; swNum = PRDecode(machineType, numStr.c_str()); - yamlDoc[kCoilsSection][bumperName][kNumberField] >> numStr; coilNum = PRDecode(machineType, numStr.c_str()); + std::string bumperName = bumpersIt->as(); + numStr = yamlDoc[kSwitchesSection][bumperName][kNumberField].as(); swNum = PRDecode(machineType, numStr.c_str()); + numStr = yamlDoc[kCoilsSection][bumperName][kNumberField].as(); coilNum = PRDecode(machineType, numStr.c_str()); ConfigureBumperRule (proc, swNum, coilNum, kBumperPulseTime); } }