COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
unitstruc Struct Reference

JSON unit type entry. More...

#include <jsondef.h>

Collaboration diagram for unitstruc:

Public Member Functions

json11::Json to_json () const
 Convert class contents to JSON object. More...
 
void from_json (const string &s)
 Set class contents from JSON string. More...
 

Public Attributes

string name = ""
 JSON Unit Name. More...
 
uint16_t type = JSON_UNIT_TYPE_IDENTITY
 JSON Unit conversion type. More...
 
float p0 = 0.f
 0th derivative term More...
 
float p1 = 0.f
 1th derivative term More...
 
float p2 = 0.f
 2th derivative term More...
 

Detailed Description

JSON unit type entry.

To be used in the cosmosstruc table of units. Each entry represents one specific variant of one type of unit. Each entry includes:

  • a name for the unit
  • a type for the unit conversion: 0 = identity, 1 = linear, 2 = log
  • 0th, 1st and 2nd derivative terms for any conversion

Member Function Documentation

json11::Json unitstruc::to_json ( ) const
inline

Convert class contents to JSON object.

Returns a json11 JSON object of the class

Returns
A json11 JSON object containing every member variable within the class
689  {
690  return json11::Json::object {
691  { "name", name },
692  { "type", type },
693  { "p0", p0 },
694  { "p1", p1 },
695  { "p2", p2 }
696  };
697  }
float p0
0th derivative term
Definition: jsondef.h:679
std::map< std::string, Json > object
Definition: json11.hpp:88
float p1
1th derivative term
Definition: jsondef.h:681
string name
JSON Unit Name.
Definition: jsondef.h:675
uint16_t type
JSON Unit conversion type.
Definition: jsondef.h:677
float p2
2th derivative term
Definition: jsondef.h:683
void unitstruc::from_json ( const string &  s)
inline

Set class contents from JSON string.

Parses the provided JSON-formatted string and sets the class data. String should be formatted like the string returned from to_json()

Parameters
sJSON-formatted string to set class contents to
Returns
n/a
705  {
706  string error;
707  json11::Json parsed = json11::Json::parse(s,error);
708  if(error.empty()) {
709  if(!parsed["name"].is_null()) { name = parsed["name"].string_value(); }
710  if(!parsed["type"].is_null()) { type = parsed["type"].int_value(); }
711  if(!parsed["p0"].is_null()) { p0 = parsed["p0"].number_value(); }
712  if(!parsed["p1"].is_null()) { p1 = parsed["p1"].number_value(); }
713  if(!parsed["p2"].is_null()) { p2 = parsed["p2"].number_value(); }
714  } else {
715  cerr<<"ERROR: <"<<error<<">"<<endl;
716  }
717  return;
718  }
float p0
0th derivative term
Definition: jsondef.h:679
Definition: json11.hpp:79
float p1
1th derivative term
Definition: jsondef.h:681
string name
JSON Unit Name.
Definition: jsondef.h:675
static Json parse(const std::string &in, std::string &err, JsonParse strategy=JsonParse::STANDARD)
uint16_t type
JSON Unit conversion type.
Definition: jsondef.h:677
const std::string & string_value() const
Definition: json11.cpp:283
float p2
2th derivative term
Definition: jsondef.h:683
int int_value() const
Definition: json11.cpp:281
double number_value() const
Definition: json11.cpp:280

Member Data Documentation

string unitstruc::name = ""

JSON Unit Name.

uint16_t unitstruc::type = JSON_UNIT_TYPE_IDENTITY

JSON Unit conversion type.

float unitstruc::p0 = 0.f

0th derivative term

float unitstruc::p1 = 0.f

1th derivative term

float unitstruc::p2 = 0.f

2th derivative term


The documentation for this struct was generated from the following file: