src/alfalfa/AlfalfaMeter.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*********************************************************************************************************************** | ||
| 2 | * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC. | ||
| 3 | * See also https://openstudio.net/license | ||
| 4 | ***********************************************************************************************************************/ | ||
| 5 | |||
| 6 | #include "AlfalfaMeter.hpp" | ||
| 7 | |||
| 8 | #include "../utilities/idd/IddObject.hpp" | ||
| 9 | #include "../utilities/idd/IddEnums.hpp" | ||
| 10 | |||
| 11 | #include <utilities/idd/OS_Output_Meter_FieldEnums.hxx> | ||
| 12 | #include <utilities/idd/Output_Meter_FieldEnums.hxx> | ||
| 13 | #include <utilities/idd/IddEnums.hxx> | ||
| 14 | |||
| 15 | #include <fmt/format.h> | ||
| 16 | |||
| 17 | namespace openstudio { | ||
| 18 | namespace alfalfa { | ||
| 19 |
1/1✓ Branch 2 taken 11 times.
|
11 | AlfalfaMeter::AlfalfaMeter(const std::string& meter_name) : m_meter_name(meter_name) { |
| 20 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
|
11 | if (meter_name.empty()) { |
| 21 | ✗ | throw std::runtime_error("Error creating AlfalfaMeter: meter_name must be non-empty"); | |
| 22 | } | ||
| 23 | 11 | } | |
| 24 | |||
| 25 | 12 | AlfalfaMeter::AlfalfaMeter(const IdfObject& output_meter) { | |
| 26 |
2/2✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
|
12 | const IddObjectType idd_type = output_meter.iddObject().type(); |
| 27 |
3/3✓ Branch 1 taken 12 times.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 6 times.
|
12 | if (idd_type == IddObjectType::Output_Meter) { |
| 28 |
2/2✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
|
6 | m_meter_name = output_meter.getString(Output_MeterFields::KeyName).value_or(""); |
| 29 |
2/3✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
|
6 | } else if (idd_type == IddObjectType::OS_Output_Meter) { |
| 30 |
2/2✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
|
6 | m_meter_name = output_meter.getString(OS_Output_MeterFields::Name).value_or(""); |
| 31 | } else { | ||
| 32 | ✗ | throw std::runtime_error(fmt::format("Error creating AlfalfaMeter: {} is not a supported object type", idd_type.valueDescription())); | |
| 33 | } | ||
| 34 | |||
| 35 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 2 taken 8 times.
|
12 | if (m_meter_name.empty()) { |
| 36 |
1/1✓ Branch 2 taken 4 times.
|
4 | throw std::runtime_error("Error creating AlfalfaMeter: Object is missing a meter name"); |
| 37 | } | ||
| 38 | 16 | } | |
| 39 | |||
| 40 | 1 | std::string AlfalfaMeter::deriveName() const { | |
| 41 | 1 | return "Meter for " + m_meter_name; | |
| 42 | } | ||
| 43 | |||
| 44 | 28 | Json::Value AlfalfaMeter::toJSON() const { | |
| 45 | 28 | Json::Value parameters; | |
| 46 |
2/2✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
|
28 | parameters["meter_name"] = m_meter_name; |
| 47 | |||
| 48 | 28 | return parameters; | |
| 49 | ✗ | } | |
| 50 | |||
| 51 | ✗ | std::string AlfalfaMeter::meterName() const { | |
| 52 | ✗ | return m_meter_name; | |
| 53 | } | ||
| 54 | |||
| 55 | 31 | bool AlfalfaMeter::acceptsObjectType(const IddObjectType& idd_type) { | |
| 56 |
4/4✓ Branch 1 taken 27 times.
✓ Branch 2 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 23 times.
|
31 | return idd_type.value() == IddObjectType::OS_Output_Meter || idd_type.value() == IddObjectType::Output_Meter; |
| 57 | } | ||
| 58 | |||
| 59 | } // namespace alfalfa | ||
| 60 | } // namespace openstudio | ||
| 61 |