OpenStudio:utilities
Loading...
Searching...
No Matches
openstudio::Attribute Class Reference

#include <Attribute.hpp>

Public Types

using ImplType = detail::Attribute_Impl
 

Public Member Functions

 Attribute (const Attribute &other)
 
 Attribute (const openstudio::UUID &uuid, const openstudio::UUID &versionUUID, const std::string &name, const boost::optional< std::string > &displayName, bool value, const boost::optional< std::string > &units, const std::string &source=std::string())
 
 Attribute (const openstudio::UUID &uuid, const openstudio::UUID &versionUUID, const std::string &name, const boost::optional< std::string > &displayName, const char *value, const boost::optional< std::string > &units, const std::string &source=std::string())
 
 Attribute (const openstudio::UUID &uuid, const openstudio::UUID &versionUUID, const std::string &name, const boost::optional< std::string > &displayName, const std::string &value, const boost::optional< std::string > &units, const std::string &source=std::string())
 
 Attribute (const openstudio::UUID &uuid, const openstudio::UUID &versionUUID, const std::string &name, const boost::optional< std::string > &displayName, const std::vector< openstudio::Attribute > &value, const boost::optional< std::string > &units, const std::string &source=std::string())
 
 Attribute (const openstudio::UUID &uuid, const openstudio::UUID &versionUUID, const std::string &name, const boost::optional< std::string > &displayName, double value, const boost::optional< std::string > &units, const std::string &source=std::string())
 
 Attribute (const openstudio::UUID &uuid, const openstudio::UUID &versionUUID, const std::string &name, const boost::optional< std::string > &displayName, int value, const boost::optional< std::string > &units, const std::string &source=std::string())
 
 Attribute (const openstudio::UUID &uuid, const openstudio::UUID &versionUUID, const std::string &name, const boost::optional< std::string > &displayName, unsigned value, const boost::optional< std::string > &units, const std::string &source=std::string())
 
 Attribute (const pugi::xml_node &element)
 
 Attribute (const std::string &name, bool value)
 constructors
 
 Attribute (const std::string &name, bool value, const boost::optional< std::string > &units)
 
 Attribute (const std::string &name, bool value, const std::string &units)
 
 Attribute (const std::string &name, const char *value)
 
 Attribute (const std::string &name, const char *value, const boost::optional< std::string > &units)
 
 Attribute (const std::string &name, const char *value, const std::string &units)
 
 Attribute (const std::string &name, const std::string &value)
 
 Attribute (const std::string &name, const std::string &value, const boost::optional< std::string > &units)
 
 Attribute (const std::string &name, const std::string &value, const std::string &units)
 
 Attribute (const std::string &name, const std::vector< openstudio::Attribute > &value)
 
 Attribute (const std::string &name, const std::vector< openstudio::Attribute > &value, const boost::optional< std::string > &units)
 
 Attribute (const std::string &name, const std::vector< openstudio::Attribute > &value, const std::string &units)
 
 Attribute (const std::string &name, double value)
 
 Attribute (const std::string &name, double value, const boost::optional< std::string > &units)
 
 Attribute (const std::string &name, double value, const std::string &units)
 
 Attribute (const std::string &name, int value)
 
 Attribute (const std::string &name, int value, const boost::optional< std::string > &units)
 
 Attribute (const std::string &name, int value, const std::string &units)
 
 Attribute (const std::string &name, unsigned value)
 
 Attribute (const std::string &name, unsigned value, const boost::optional< std::string > &units)
 
 Attribute (const std::string &name, unsigned value, const std::string &units)
 
template<typename T >
cast () const
 cast to type T, can throw std::bad_cast
 
void clearDisplayName ()
 clear the display name
 
void clearSource ()
 clear the data source
 
Attribute clone () const
 
boost::optional< std::string > displayName (bool returnName=false) const
 get the display name.
 
boost::optional< AttributefindChildByName (const std::string &name) const
 find child attribute by name
 
bool hasValue () const
 Returns true if this Attribute value has been set.
 
std::string name () const
 get the name
 
bool operator== (const Attribute &other) const
 comparison
 
template<typename T >
boost::optional< T > optionalCast () const
 cast to optional of type T
 
bool saveToXml (const openstudio::path &path) const
 write object and all children out as xml to path.
 
bool setDisplayName (const std::string &displayName)
 set the display name
 
void setSource (const std::string &source)
 set the data source
 
bool setUnits (const std::string &units)
 set the units
 
void setValue (bool value)
 set value. throws if wrong type.
 
void setValue (const char *value)
 set value. throws if wrong type.
 
void setValue (const std::string &value)
 set value. throws if wrong type.
 
void setValue (const std::vector< Attribute > &value)
 set value. throws if wrong type.
 
void setValue (double value)
 set value. throws if wrong type.
 
void setValue (int value)
 set value. throws if wrong type.
 
void setValue (unsigned value)
 set value. throws if wrong type.
 
std::string source () const
 get the (optional) data source
 
Json::Value toJSON (bool short_version=true) const
 
std::string toJSONString () const
 
std::string toString () const
 If attribute is a simple type (non-vector), prints attribute's value to std::string as simply as possible.
 
boost::optional< std::string > units () const
 get the units
 
openstudio::UUID uuid () const
 
std::vector< AttributevalueAsAttributeVector () const
 get value as attribute vector
 
bool valueAsBoolean () const
 get value as a bool
 
double valueAsDouble () const
 get value as double
 
int valueAsInteger () const
 get value as int
 
Json::Value valueAsJSON () const
 
std::string valueAsString () const
 get value as string
 
unsigned valueAsUnsigned () const
 get value as unsigned
 
AttributeValueType valueType () const
 get the attribute value type
 
openstudio::UUID versionUUID () const
 
virtual ~Attribute ()=default
 

Static Public Member Functions

static boost::optional< AttributeloadFromXml (const openstudio::path &xmlPath)
 static constructor from xml
 

Protected Member Functions

 Attribute (const std::shared_ptr< detail::Attribute_Impl > &impl)
 
pugi::xml_document toXml () const
 write object and all children to xml
 

Related Symbols

(Note that these are not member symbols.)

using AttributeVector = std::vector<Attribute>
 
Attribute createAttributeFromVector (const std::string &name, const std::vector< double > &value)
 
Attribute createAttributeFromVector (const std::string &name, const std::vector< int > &value)
 
std::vector< double > getDoubleVectorFromAttribute (const Attribute &attribute)
 
std::vector< intgetIntVectorFromAttribute (const Attribute &attribute)
 
std::ostream & operator<< (std::ostream &os, const Attribute &attribute)
 Prints Attribute XML to os.
 
using OptionalAttribute = boost::optional<Attribute>
 

Detailed Description

An attribute is a name value pair where the value can be a bool, double, int, string, or vector of other attributes.

The ability for an attribute value to be a vector of other attributes allows for flexible, hierarchical structures. Our convention is that attributes which correspond to plain old data (int, string, etc) are named in lower camel case, this corresponds to a member or variable name. Attributes of vector type are named in upper camel case to correspond to a class or struct name.

Member Typedef Documentation

◆ ImplType

using openstudio::Attribute::ImplType = detail::Attribute_Impl

Constructor & Destructor Documentation

◆ Attribute() [1/31]

openstudio::Attribute::Attribute ( const std::string & name,
bool value )

constructors

◆ Attribute() [2/31]

openstudio::Attribute::Attribute ( const std::string & name,
bool value,
const std::string & units )

◆ Attribute() [3/31]

openstudio::Attribute::Attribute ( const std::string & name,
bool value,
const boost::optional< std::string > & units )

◆ Attribute() [4/31]

openstudio::Attribute::Attribute ( const openstudio::UUID & uuid,
const openstudio::UUID & versionUUID,
const std::string & name,
const boost::optional< std::string > & displayName,
bool value,
const boost::optional< std::string > & units,
const std::string & source = std::string() )

◆ Attribute() [5/31]

openstudio::Attribute::Attribute ( const std::string & name,
double value )

◆ Attribute() [6/31]

openstudio::Attribute::Attribute ( const std::string & name,
double value,
const std::string & units )

◆ Attribute() [7/31]

openstudio::Attribute::Attribute ( const std::string & name,
double value,
const boost::optional< std::string > & units )

◆ Attribute() [8/31]

openstudio::Attribute::Attribute ( const openstudio::UUID & uuid,
const openstudio::UUID & versionUUID,
const std::string & name,
const boost::optional< std::string > & displayName,
double value,
const boost::optional< std::string > & units,
const std::string & source = std::string() )

◆ Attribute() [9/31]

openstudio::Attribute::Attribute ( const std::string & name,
int value )

◆ Attribute() [10/31]

openstudio::Attribute::Attribute ( const std::string & name,
int value,
const std::string & units )

◆ Attribute() [11/31]

openstudio::Attribute::Attribute ( const std::string & name,
int value,
const boost::optional< std::string > & units )

◆ Attribute() [12/31]

openstudio::Attribute::Attribute ( const openstudio::UUID & uuid,
const openstudio::UUID & versionUUID,
const std::string & name,
const boost::optional< std::string > & displayName,
int value,
const boost::optional< std::string > & units,
const std::string & source = std::string() )

◆ Attribute() [13/31]

openstudio::Attribute::Attribute ( const std::string & name,
unsigned value )

◆ Attribute() [14/31]

openstudio::Attribute::Attribute ( const std::string & name,
unsigned value,
const std::string & units )

◆ Attribute() [15/31]

openstudio::Attribute::Attribute ( const std::string & name,
unsigned value,
const boost::optional< std::string > & units )

◆ Attribute() [16/31]

openstudio::Attribute::Attribute ( const openstudio::UUID & uuid,
const openstudio::UUID & versionUUID,
const std::string & name,
const boost::optional< std::string > & displayName,
unsigned value,
const boost::optional< std::string > & units,
const std::string & source = std::string() )

◆ Attribute() [17/31]

openstudio::Attribute::Attribute ( const std::string & name,
const char * value )

◆ Attribute() [18/31]

openstudio::Attribute::Attribute ( const std::string & name,
const char * value,
const std::string & units )

◆ Attribute() [19/31]

openstudio::Attribute::Attribute ( const std::string & name,
const char * value,
const boost::optional< std::string > & units )

◆ Attribute() [20/31]

openstudio::Attribute::Attribute ( const openstudio::UUID & uuid,
const openstudio::UUID & versionUUID,
const std::string & name,
const boost::optional< std::string > & displayName,
const char * value,
const boost::optional< std::string > & units,
const std::string & source = std::string() )

◆ Attribute() [21/31]

openstudio::Attribute::Attribute ( const std::string & name,
const std::string & value )

◆ Attribute() [22/31]

openstudio::Attribute::Attribute ( const std::string & name,
const std::string & value,
const std::string & units )

◆ Attribute() [23/31]

openstudio::Attribute::Attribute ( const std::string & name,
const std::string & value,
const boost::optional< std::string > & units )

◆ Attribute() [24/31]

openstudio::Attribute::Attribute ( const openstudio::UUID & uuid,
const openstudio::UUID & versionUUID,
const std::string & name,
const boost::optional< std::string > & displayName,
const std::string & value,
const boost::optional< std::string > & units,
const std::string & source = std::string() )

◆ Attribute() [25/31]

openstudio::Attribute::Attribute ( const std::string & name,
const std::vector< openstudio::Attribute > & value )

◆ Attribute() [26/31]

openstudio::Attribute::Attribute ( const std::string & name,
const std::vector< openstudio::Attribute > & value,
const std::string & units )

◆ Attribute() [27/31]

openstudio::Attribute::Attribute ( const std::string & name,
const std::vector< openstudio::Attribute > & value,
const boost::optional< std::string > & units )

◆ Attribute() [28/31]

openstudio::Attribute::Attribute ( const openstudio::UUID & uuid,
const openstudio::UUID & versionUUID,
const std::string & name,
const boost::optional< std::string > & displayName,
const std::vector< openstudio::Attribute > & value,
const boost::optional< std::string > & units,
const std::string & source = std::string() )

◆ ~Attribute()

virtual openstudio::Attribute::~Attribute ( )
virtualdefault

◆ Attribute() [29/31]

openstudio::Attribute::Attribute ( const pugi::xml_node & element)
explicit

◆ Attribute() [30/31]

openstudio::Attribute::Attribute ( const Attribute & other)

◆ Attribute() [31/31]

openstudio::Attribute::Attribute ( const std::shared_ptr< detail::Attribute_Impl > & impl)
protected

Member Function Documentation

◆ cast()

template<typename T >
T openstudio::Attribute::cast ( ) const
inline

cast to type T, can throw std::bad_cast

◆ clearDisplayName()

void openstudio::Attribute::clearDisplayName ( )

clear the display name

◆ clearSource()

void openstudio::Attribute::clearSource ( )

clear the data source

◆ clone()

Attribute openstudio::Attribute::clone ( ) const

◆ displayName()

boost::optional< std::string > openstudio::Attribute::displayName ( bool returnName = false) const

get the display name.

if returnName and the display name is empty, will return name() instead.

◆ findChildByName()

boost::optional< Attribute > openstudio::Attribute::findChildByName ( const std::string & name) const

find child attribute by name

◆ hasValue()

bool openstudio::Attribute::hasValue ( ) const

Returns true if this Attribute value has been set.

◆ loadFromXml()

static boost::optional< Attribute > openstudio::Attribute::loadFromXml ( const openstudio::path & xmlPath)
static

static constructor from xml

◆ name()

std::string openstudio::Attribute::name ( ) const

get the name

◆ operator==()

bool openstudio::Attribute::operator== ( const Attribute & other) const

comparison

◆ optionalCast()

template<typename T >
boost::optional< T > openstudio::Attribute::optionalCast ( ) const
inline

cast to optional of type T

◆ saveToXml()

bool openstudio::Attribute::saveToXml ( const openstudio::path & path) const

write object and all children out as xml to path.

◆ setDisplayName()

bool openstudio::Attribute::setDisplayName ( const std::string & displayName)

set the display name

◆ setSource()

void openstudio::Attribute::setSource ( const std::string & source)

set the data source

◆ setUnits()

bool openstudio::Attribute::setUnits ( const std::string & units)

set the units

◆ setValue() [1/7]

void openstudio::Attribute::setValue ( bool value)

set value. throws if wrong type.

◆ setValue() [2/7]

void openstudio::Attribute::setValue ( const char * value)

set value. throws if wrong type.

◆ setValue() [3/7]

void openstudio::Attribute::setValue ( const std::string & value)

set value. throws if wrong type.

◆ setValue() [4/7]

void openstudio::Attribute::setValue ( const std::vector< Attribute > & value)

set value. throws if wrong type.

◆ setValue() [5/7]

void openstudio::Attribute::setValue ( double value)

set value. throws if wrong type.

◆ setValue() [6/7]

void openstudio::Attribute::setValue ( int value)

set value. throws if wrong type.

◆ setValue() [7/7]

void openstudio::Attribute::setValue ( unsigned value)

set value. throws if wrong type.

◆ source()

std::string openstudio::Attribute::source ( ) const

get the (optional) data source

◆ toJSON()

Json::Value openstudio::Attribute::toJSON ( bool short_version = true) const

◆ toJSONString()

std::string openstudio::Attribute::toJSONString ( ) const

◆ toString()

std::string openstudio::Attribute::toString ( ) const

If attribute is a simple type (non-vector), prints attribute's value to std::string as simply as possible.

Numeric types print in high precision. Attribute vectors are printed as XML.

◆ toXml()

pugi::xml_document openstudio::Attribute::toXml ( ) const
protected

write object and all children to xml

◆ units()

boost::optional< std::string > openstudio::Attribute::units ( ) const

get the units

◆ uuid()

openstudio::UUID openstudio::Attribute::uuid ( ) const

◆ valueAsAttributeVector()

std::vector< Attribute > openstudio::Attribute::valueAsAttributeVector ( ) const

get value as attribute vector

◆ valueAsBoolean()

bool openstudio::Attribute::valueAsBoolean ( ) const

get value as a bool

◆ valueAsDouble()

double openstudio::Attribute::valueAsDouble ( ) const

get value as double

◆ valueAsInteger()

int openstudio::Attribute::valueAsInteger ( ) const

get value as int

◆ valueAsJSON()

Json::Value openstudio::Attribute::valueAsJSON ( ) const

◆ valueAsString()

std::string openstudio::Attribute::valueAsString ( ) const

get value as string

◆ valueAsUnsigned()

unsigned openstudio::Attribute::valueAsUnsigned ( ) const

get value as unsigned

◆ valueType()

AttributeValueType openstudio::Attribute::valueType ( ) const

get the attribute value type

◆ versionUUID()

openstudio::UUID openstudio::Attribute::versionUUID ( ) const

Friends And Related Symbol Documentation

◆ AttributeVector

using AttributeVector = std::vector<Attribute>
related

◆ createAttributeFromVector() [1/2]

Attribute createAttributeFromVector ( const std::string & name,
const std::vector< double > & value )
related

◆ createAttributeFromVector() [2/2]

Attribute createAttributeFromVector ( const std::string & name,
const std::vector< int > & value )
related

◆ getDoubleVectorFromAttribute()

std::vector< double > getDoubleVectorFromAttribute ( const Attribute & attribute)
related

◆ getIntVectorFromAttribute()

std::vector< int > getIntVectorFromAttribute ( const Attribute & attribute)
related

◆ operator<<()

std::ostream & operator<< ( std::ostream & os,
const Attribute & attribute )
related

Prints Attribute XML to os.

◆ OptionalAttribute

using OptionalAttribute = boost::optional<Attribute>
related