Matt Spinler | b666433 | 2019-09-10 15:24:10 -0500 | [diff] [blame] | 1 | #include "mtms.hpp" |
| 2 | |
| 3 | namespace openpower |
| 4 | { |
| 5 | namespace pels |
| 6 | { |
| 7 | |
| 8 | MTMS::MTMS() |
| 9 | { |
| 10 | memset(_machineTypeAndModel.data(), 0, mtmSize); |
| 11 | memset(_serialNumber.data(), 0, snSize); |
| 12 | } |
| 13 | |
| 14 | MTMS::MTMS(const std::string& typeModel, const std::string& serialNumber) |
| 15 | { |
| 16 | memset(_machineTypeAndModel.data(), 0, mtmSize); |
| 17 | memset(_serialNumber.data(), 0, snSize); |
| 18 | |
| 19 | // Copy in as much as the fields as possible |
| 20 | for (size_t i = 0; i < mtmSize; i++) |
| 21 | { |
| 22 | if (typeModel.size() > i) |
| 23 | { |
| 24 | _machineTypeAndModel[i] = typeModel[i]; |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | for (size_t i = 0; i < snSize; i++) |
| 29 | { |
| 30 | if (serialNumber.size() > i) |
| 31 | { |
| 32 | _serialNumber[i] = serialNumber[i]; |
| 33 | } |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | MTMS::MTMS(Stream& stream) |
| 38 | { |
| 39 | for (size_t i = 0; i < mtmSize; i++) |
| 40 | { |
| 41 | stream >> _machineTypeAndModel[i]; |
| 42 | } |
| 43 | |
| 44 | for (size_t i = 0; i < snSize; i++) |
| 45 | { |
| 46 | stream >> _serialNumber[i]; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | Stream& operator<<(Stream& s, MTMS& mtms) |
| 51 | { |
| 52 | for (size_t i = 0; i < MTMS::mtmSize; i++) |
| 53 | { |
| 54 | s << mtms.machineTypeAndModel()[i]; |
| 55 | } |
| 56 | |
| 57 | for (size_t i = 0; i < MTMS::snSize; i++) |
| 58 | { |
| 59 | s << mtms.machineSerialNumber()[i]; |
| 60 | } |
| 61 | |
| 62 | return s; |
| 63 | } |
| 64 | |
| 65 | Stream& operator>>(Stream& s, MTMS& mtms) |
| 66 | { |
| 67 | for (size_t i = 0; i < MTMS::mtmSize; i++) |
| 68 | { |
| 69 | s >> mtms.machineTypeAndModel()[i]; |
| 70 | } |
| 71 | |
| 72 | for (size_t i = 0; i < MTMS::snSize; i++) |
| 73 | { |
| 74 | s >> mtms.machineSerialNumber()[i]; |
| 75 | } |
| 76 | |
| 77 | return s; |
| 78 | } |
| 79 | } // namespace pels |
| 80 | } // namespace openpower |