From 5fa14dbc99eba7031b53f580bb4db4ffa600b2b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Czy=C5=BC?= Date: Fri, 15 Nov 2019 11:48:38 +0100 Subject: [PATCH] Added display() to Peripheral --- Src/Peripheral.hpp | 53 ++++++++++++++++++++++++++++++++++++++++++---- Src/XmlParser.cpp | 3 ++- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/Src/Peripheral.hpp b/Src/Peripheral.hpp index 41f4ba7..e9666cd 100644 --- a/Src/Peripheral.hpp +++ b/Src/Peripheral.hpp @@ -11,15 +11,27 @@ enum class EAccess{ Read_Write }; -struct Field{ +struct IDisplay{ + virtual void display() = 0; +}; + +struct Field : public IDisplay{ std::string name; std::string description; unsigned int bitOffset; unsigned int bitWidth; EAccess fieldAccess; + void display() final{ + std::cout << std::endl + << "\t\tname: " << name << std::endl + << "\t\tdescription: " << description << std::endl + << "\t\tbitOffset: " << bitOffset << std::endl + << "\t\tbitWidth: " << bitWidth << std::endl + << "\t\tfieldAccess: " << (int)fieldAccess << std::endl; + } }; -struct Register{ +struct Register : public IDisplay{ std::string name; std::string description; unsigned int addressOffset; @@ -27,20 +39,53 @@ struct Register{ EAccess registerAccess; unsigned int resetValue; std::vector fields; + + void display() final{ + std::cout << std::endl + << "\tname: " << name << std::endl + << "\tdescription: " << description << std::endl + << "\taddressOffset: " << addressOffset << std::endl + << "\tsize: " << size << std::endl + << "\tregisterAccess: " << (int)registerAccess << std::endl + << "\tresetValue: " << resetValue << std::endl; + + std::cout << std::endl << "\tfields: " << std::endl; + for(auto& i : fields){ + i.display(); + } + } }; -struct AddressBlock{ +struct AddressBlock : public IDisplay{ unsigned int offset; unsigned int size; + void display() final{ + std::cout << std::endl + << "\toffset: " << offset << std::endl + << "\tsize: " << size << std::endl; + } }; -struct Peripheral{ +struct Peripheral : public IDisplay{ std::string name; std::string description; std::string groupName; unsigned int baseAddress; AddressBlock addressBlock; std::vector registers; + void display() final{ + std::cout << std::endl + << "name: " << name << std::endl + << "description: " << description << std::endl + << "groupName: " << groupName << std::endl + << "baseAddress: " << baseAddress << std::endl + << "addressBlock: "; + addressBlock.display(); + std::cout << std::endl << "registers: " << std::endl; + for(auto& i : registers){ + i.display(); + } + } }; #endif diff --git a/Src/XmlParser.cpp b/Src/XmlParser.cpp index 5e01693..6870e37 100644 --- a/Src/XmlParser.cpp +++ b/Src/XmlParser.cpp @@ -76,7 +76,6 @@ Peripheral XmlParser::parsePeripheral(tinyxml2::XMLElement* peripheralRoot){ setDeviceInfoAttrib(peripheralRoot, "description", peripheral.description); setDeviceInfoAttrib(peripheralRoot, "groupName", peripheral.groupName); setDeviceInfoAttrib(peripheralRoot, "baseAddress", peripheral.baseAddress); - peripheral.addressBlock = parseAddressBlock(peripheralRoot->FirstChildElement("addressBlock")); //Iterate over all registers and append them to peripheral @@ -93,6 +92,7 @@ Peripheral XmlParser::parsePeripheral(tinyxml2::XMLElement* peripheralRoot){ peripheral.registers.push_back(parseRegister(registerRoot->ToElement())); } } + peripheral.display(); return peripheral; } @@ -104,6 +104,7 @@ AddressBlock XmlParser::parseAddressBlock(tinyxml2::XMLElement* addressBlockRoot } else std::cout << "parseAddressBlock is nullptr!" << std::endl; + 1 / 0; return addressBlock; }