regulators: Implements support for chassis

Implements support for parsing the chassis JSON elements in the
configuration file parser.

Signed-off-by: Bob King <Bob_King@wistron.com>
Change-Id: I26e7a3f118c9fc6e0e302be20bb3e0ea63f9e1fd
diff --git a/phosphor-regulators/src/config_file_parser.hpp b/phosphor-regulators/src/config_file_parser.hpp
index 0a931d8..3ebab4b 100644
--- a/phosphor-regulators/src/config_file_parser.hpp
+++ b/phosphor-regulators/src/config_file_parser.hpp
@@ -17,6 +17,7 @@
 
 #include "action.hpp"
 #include "chassis.hpp"
+#include "device.hpp"
 #include "i2c_write_bit_action.hpp"
 #include "i2c_write_byte_action.hpp"
 #include "i2c_write_bytes_action.hpp"
@@ -172,6 +173,18 @@
 }
 
 /**
+ * Parses a JSON element containing a chassis.
+ *
+ * Returns the corresponding C++ Chassis object.
+ *
+ * Throws an exception if parsing fails.
+ *
+ * @param element JSON element
+ * @return Chassis object
+ */
+std::unique_ptr<Chassis> parseChassis(const nlohmann::json& element);
+
+/**
  * Parses a JSON element containing an array of chassis.
  *
  * Returns the corresponding C++ Chassis objects.
@@ -185,6 +198,19 @@
     parseChassisArray(const nlohmann::json& element);
 
 /**
+ * Parses a JSON element containing an array of devices.
+ *
+ * Returns the corresponding C++ Device objects.
+ *
+ * Throws an exception if parsing fails.
+ *
+ * @param element JSON element
+ * @return vector of Device objects
+ */
+std::vector<std::unique_ptr<Device>>
+    parseDeviceArray(const nlohmann::json& element);
+
+/**
  * Parses a JSON element containing a double (floating point number).
  *
  * Returns the corresponding C++ double value.
@@ -431,6 +457,26 @@
 }
 
 /**
+ * Parses a JSON element containing an unsigned integer.
+ *
+ * Returns the corresponding C++ unsigned int value.
+ *
+ * Throws an exception if parsing fails.
+ *
+ * @param element JSON element
+ * @return unsigned int value
+ */
+inline unsigned int parseUnsignedInteger(const nlohmann::json& element)
+{
+    // Verify element contains an unsigned integer
+    if (!element.is_number_unsigned())
+    {
+        throw std::invalid_argument{"Element is not an unsigned integer"};
+    }
+    return element.get<unsigned int>();
+}
+
+/**
  * Verifies that the specified JSON element is a JSON array.
  *
  * Throws an invalid_argument exception if the element is not an array.