DPsim
Attribute.cpp
1 /* Copyright 2017-2021 Institute for Automation of Complex Power Systems,
2  * EONERC, RWTH Aachen University
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at https://mozilla.org/MPL/2.0/.
7  *********************************************************************************/
8 
9 #include <iostream>
10 
11 #include <dpsim-models/Attribute.h>
12 #include <dpsim-models/Config.h>
13 
14 using namespace CPS;
15 
16 std::ostream &operator<<(std::ostream &output, AttributeBase &attr) {
17  output << attr.toString();
18  return output;
19 }
20 
24 template <> String Attribute<Real>::toString() {
25  return std::to_string(this->get());
26 }
27 
28 template <> String Attribute<Complex>::toString() {
29  std::stringstream ss;
31  ss.precision(2);
32  ss << this->get().real() << "+" << this->get().imag() << "i";
33  return ss.str();
34 }
35 
36 template <> String Attribute<String>::toString() { return this->get(); }
37 
38 template class CPS::Attribute<Real>;
39 template class CPS::Attribute<Complex>;
40 template class CPS::Attribute<String>;
virtual String toString()=0
String toString() override
Fallback method for all attribute types not covered by the specifications in Attribute....
Definition: Attribute.h:307