OpenStudio:utilities
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Related Functions | List of all members
openstudio::Attribute Class Reference

#include <Attribute.hpp>

Public Types

typedef detail::Attribute_Impl ImplType
 

Public Member Functions

 Attribute (const std::string &name, bool value)
 constructors More...
 
 Attribute (const std::string &name, bool value, const std::string &units)
 
 Attribute (const std::string &name, bool value, const boost::optional< std::string > &units)
 
 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 std::string &name, double value)
 
 Attribute (const std::string &name, double value, const std::string &units)
 
 Attribute (const std::string &name, double value, const boost::optional< std::string > &units)
 
 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 std::string &name, const OSOptionalQuantity &value)
 Upon construction, will be of type Quantity or Unit, as appropriate. More...
 
 Attribute (const std::string &name, const Quantity &value)
 
 Attribute (const openstudio::UUID &uuid, const openstudio::UUID &versionUUID, const std::string &name, const boost::optional< std::string > &displayName, const Quantity &value, const std::string &source=std::string())
 
 Attribute (const std::string &name, const Unit &value)
 
 Attribute (const openstudio::UUID &uuid, const openstudio::UUID &versionUUID, const std::string &name, const boost::optional< std::string > &displayName, const Unit &value, const std::string &source=std::string())
 
 Attribute (const std::string &name, int value)
 
 Attribute (const std::string &name, int value, const std::string &units)
 
 Attribute (const std::string &name, int value, const boost::optional< std::string > &units)
 
 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 std::string &name, unsigned value)
 
 Attribute (const std::string &name, unsigned value, const std::string &units)
 
 Attribute (const std::string &name, unsigned value, const boost::optional< std::string > &units)
 
 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 std::string &name, const char *value)
 
 Attribute (const std::string &name, const char *value, const std::string &units)
 
 Attribute (const std::string &name, const char *value, const boost::optional< std::string > &units)
 
 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 std::string &name, const std::string &value)
 
 Attribute (const std::string &name, const std::string &value, const std::string &units)
 
 Attribute (const std::string &name, const std::string &value, const boost::optional< std::string > &units)
 
 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 std::string &name, const std::vector< openstudio::Attribute > &value)
 
 Attribute (const std::string &name, const std::vector< openstudio::Attribute > &value, const std::string &units)
 
 Attribute (const std::string &name, const std::vector< openstudio::Attribute > &value, const boost::optional< std::string > &units)
 
 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 QDomElement &element)
 
 Attribute (const Attribute &other)
 
template<typename T >
cast () const
 cast to type T, can throw std::bad_cast More...
 
void clearDisplayName ()
 clear the display name More...
 
void clearSource ()
 clear the data source More...
 
Attribute clone () const
 
boost::optional< std::string > displayName (bool returnName=false) const
 get the display name. More...
 
boost::optional< AttributefindChildByName (const std::string &name) const
 find child attribute by name More...
 
std::string name () const
 get the name More...
 
bool operator== (const Attribute &other) const
 comparison More...
 
template<typename T >
boost::optional< T > optionalCast () const
 cast to optional of type T More...
 
bool saveToXml (const openstudio::path &path) const
 write object and all children out as xml to path. More...
 
bool setDisplayName (const std::string &displayName)
 set the display name More...
 
void setSource (const std::string &source)
 set the data source More...
 
bool setUnits (const std::string &units)
 set the units More...
 
void setValue (bool value)
 set value. throws if wrong type. More...
 
void setValue (int value)
 set value. throws if wrong type. More...
 
void setValue (unsigned value)
 set value. throws if wrong type. More...
 
void setValue (double value)
 set value. throws if wrong type. More...
 
void setValue (const Quantity &value)
 set value. throws if wrong type. More...
 
void setValue (const Unit &value)
 set value. throws if wrong type. More...
 
void setValue (const char *value)
 set value. throws if wrong type. More...
 
void setValue (const std::string &value)
 set value. throws if wrong type. More...
 
void setValue (const std::vector< Attribute > &value)
 set value. throws if wrong type. More...
 
void setValue (const QVariant &value)
 
std::string source () const
 get the (optional) data source More...
 
std::string toString () const
 If attribute is a simple type (non-vector), prints attribute's value to std::string as simply as possible. More...
 
QDomDocument toXml () const
 write object and all children to xml More...
 
boost::optional< std::string > units () const
 get the units More...
 
openstudio::UUID uuid () const
 
std::vector< AttributevalueAsAttributeVector () const
 get value as attribute vector More...
 
bool valueAsBoolean () const
 get value as a bool More...
 
double valueAsDouble () const
 get value as double More...
 
int valueAsInteger () const
 get value as int More...
 
Quantity valueAsQuantity () const
 get value as Quantity More...
 
QVariant valueAsQVariant () const
 get value as qvariant More...
 
std::string valueAsString () const
 get value as string More...
 
Unit valueAsUnit () const
 get value as Unit More...
 
unsigned valueAsUnsigned () const
 get value as unsigned More...
 
AttributeValueType valueType () const
 get the attribute value type More...
 
openstudio::UUID versionUUID () const
 
virtual ~Attribute ()
 

Static Public Member Functions

static boost::optional< AttributefromQVariant (const std::string &name, const QVariant &value, const boost::optional< std::string > &units=boost::none)
 static constructor from QVariant More...
 
static boost::optional< AttributeloadFromXml (const openstudio::path &path)
 static constructor from xml More...
 
static boost::optional< AttributeloadFromXml (const QDomDocument &doc)
 static constructor from loaded xml More...
 

Protected Member Functions

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

Related Functions

(Note that these are not member functions.)

typedef std::vector< AttributeAttributeVector
 
Attribute createAttributeFromVector (const std::string &name, std::vector< int > value)
 
Attribute createAttributeFromVector (const std::string &name, std::vector< double > value)
 
std::vector< double > getDoubleVectorFromAttribute (const Attribute &attribute)
 
std::vector< intgetIntVectorFromAttribute (const Attribute &attribute)
 
bool isConsistent (const Attribute &candidate, const AttributeDescription &description)
 Returns true if candidate and description have matching names and types. More...
 
std::ostream & operator<< (std::ostream &os, const Attribute &attribute)
 Prints Attribute XML to os. More...
 
typedef boost::optional
< Attribute
OptionalAttribute
 
bool prepareForDisplay (Attribute &attribute, const AttributeDescription &description)
 Copies description's display name over to attribute. More...
 
bool saveJSON (const std::vector< Attribute > &attributes, const openstudio::path &p, bool overwrite=false)
 Saves attributes in a flat json file. More...
 
std::ostream & toJSON (const std::vector< Attribute > &attributes, std::ostream &os)
 Puts attributes out to os in a flat json format. More...
 
std::string toJSON (const std::vector< Attribute > &attributes)
 Returns attributes as a string in a flat json format. More...
 
std::string toJSONWithoutMetadata (const std::vector< Attribute > &attributes)
 Returns attributes as a string in a flat json format. More...
 
std::vector< AttributetoVectorOfAttribute (const openstudio::path &pathToJson)
 Deserializes the flat attribute json format. More...
 
std::vector< AttributetoVectorOfAttribute (std::istream &json)
 Deserializes the flat attribute json format. More...
 
std::vector< AttributetoVectorOfAttribute (const std::string &json)
 Deserializes the flat attribute json format. More...
 

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

typedef detail::Attribute_Impl openstudio::Attribute::ImplType

Constructor & Destructor Documentation

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

constructors

openstudio::Attribute::Attribute ( const std::string &  name,
bool  value,
const std::string &  units 
)
openstudio::Attribute::Attribute ( const std::string &  name,
bool  value,
const boost::optional< std::string > &  units 
)
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() 
)
openstudio::Attribute::Attribute ( const std::string &  name,
double  value 
)
openstudio::Attribute::Attribute ( const std::string &  name,
double  value,
const std::string &  units 
)
openstudio::Attribute::Attribute ( const std::string &  name,
double  value,
const boost::optional< std::string > &  units 
)
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() 
)
openstudio::Attribute::Attribute ( const std::string &  name,
const OSOptionalQuantity value 
)

Upon construction, will be of type Quantity or Unit, as appropriate.

openstudio::Attribute::Attribute ( const std::string &  name,
const Quantity value 
)
openstudio::Attribute::Attribute ( const openstudio::UUID uuid,
const openstudio::UUID versionUUID,
const std::string &  name,
const boost::optional< std::string > &  displayName,
const Quantity value,
const std::string &  source = std::string() 
)
openstudio::Attribute::Attribute ( const std::string &  name,
const Unit value 
)
openstudio::Attribute::Attribute ( const openstudio::UUID uuid,
const openstudio::UUID versionUUID,
const std::string &  name,
const boost::optional< std::string > &  displayName,
const Unit value,
const std::string &  source = std::string() 
)
openstudio::Attribute::Attribute ( const std::string &  name,
int  value 
)
openstudio::Attribute::Attribute ( const std::string &  name,
int  value,
const std::string &  units 
)
openstudio::Attribute::Attribute ( const std::string &  name,
int  value,
const boost::optional< std::string > &  units 
)
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() 
)
openstudio::Attribute::Attribute ( const std::string &  name,
unsigned  value 
)
openstudio::Attribute::Attribute ( const std::string &  name,
unsigned  value,
const std::string &  units 
)
openstudio::Attribute::Attribute ( const std::string &  name,
unsigned  value,
const boost::optional< std::string > &  units 
)
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() 
)
openstudio::Attribute::Attribute ( const std::string &  name,
const char *  value 
)
openstudio::Attribute::Attribute ( const std::string &  name,
const char *  value,
const std::string &  units 
)
openstudio::Attribute::Attribute ( const std::string &  name,
const char *  value,
const boost::optional< std::string > &  units 
)
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() 
)
openstudio::Attribute::Attribute ( const std::string &  name,
const std::string &  value 
)
openstudio::Attribute::Attribute ( const std::string &  name,
const std::string &  value,
const std::string &  units 
)
openstudio::Attribute::Attribute ( const std::string &  name,
const std::string &  value,
const boost::optional< std::string > &  units 
)
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() 
)
openstudio::Attribute::Attribute ( const std::string &  name,
const std::vector< openstudio::Attribute > &  value 
)
openstudio::Attribute::Attribute ( const std::string &  name,
const std::vector< openstudio::Attribute > &  value,
const std::string &  units 
)
openstudio::Attribute::Attribute ( const std::string &  name,
const std::vector< openstudio::Attribute > &  value,
const boost::optional< std::string > &  units 
)
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() 
)
virtual openstudio::Attribute::~Attribute ( )
inlinevirtual
openstudio::Attribute::Attribute ( const QDomElement &  element)
explicit
openstudio::Attribute::Attribute ( const Attribute other)
openstudio::Attribute::Attribute ( const std::shared_ptr< detail::Attribute_Impl > &  impl)
protected

Member Function Documentation

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

cast to type T, can throw std::bad_cast

void openstudio::Attribute::clearDisplayName ( )

clear the display name

void openstudio::Attribute::clearSource ( )

clear the data source

Attribute openstudio::Attribute::clone ( ) const
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.

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

find child attribute by name

static boost::optional<Attribute> openstudio::Attribute::fromQVariant ( const std::string &  name,
const QVariant &  value,
const boost::optional< std::string > &  units = boost::none 
)
static

static constructor from QVariant

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

static constructor from xml

static boost::optional<Attribute> openstudio::Attribute::loadFromXml ( const QDomDocument &  doc)
static

static constructor from loaded xml

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

get the name

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

comparison

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

cast to optional of type T

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

write object and all children out as xml to path.

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

set the display name

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

set the data source

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

set the units

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

set value. throws if wrong type.

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

set value. throws if wrong type.

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

set value. throws if wrong type.

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

set value. throws if wrong type.

void openstudio::Attribute::setValue ( const Quantity value)

set value. throws if wrong type.

void openstudio::Attribute::setValue ( const Unit value)

set value. throws if wrong type.

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

set value. throws if wrong type.

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

set value. throws if wrong type.

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

set value. throws if wrong type.

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

get the (optional) data source

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.

QDomDocument openstudio::Attribute::toXml ( ) const

write object and all children to xml

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

get the units

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

get value as attribute vector

bool openstudio::Attribute::valueAsBoolean ( ) const

get value as a bool

double openstudio::Attribute::valueAsDouble ( ) const

get value as double

int openstudio::Attribute::valueAsInteger ( ) const

get value as int

Quantity openstudio::Attribute::valueAsQuantity ( ) const

get value as Quantity

QVariant openstudio::Attribute::valueAsQVariant ( ) const

get value as qvariant

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

get value as string

Unit openstudio::Attribute::valueAsUnit ( ) const

get value as Unit

unsigned openstudio::Attribute::valueAsUnsigned ( ) const

get value as unsigned

AttributeValueType openstudio::Attribute::valueType ( ) const

get the attribute value type

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

Friends And Related Function Documentation

typedef std::vector<Attribute> AttributeVector
related
Attribute createAttributeFromVector ( const std::string &  name,
std::vector< int value 
)
related
Attribute createAttributeFromVector ( const std::string &  name,
std::vector< double >  value 
)
related
std::vector< double > getDoubleVectorFromAttribute ( const Attribute attribute)
related
std::vector< int > getIntVectorFromAttribute ( const Attribute attribute)
related
bool isConsistent ( const Attribute candidate,
const AttributeDescription description 
)
related

Returns true if candidate and description have matching names and types.

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

Prints Attribute XML to os.

typedef boost::optional<Attribute> OptionalAttribute
related
bool prepareForDisplay ( Attribute attribute,
const AttributeDescription description 
)
related

Copies description's display name over to attribute.

Will return false if !isConsistent(attribute,description).

bool saveJSON ( const std::vector< Attribute > &  attributes,
const openstudio::path &  p,
bool  overwrite = false 
)
related

Saves attributes in a flat json file.

Discards uuid and version_uuid information. Recasts Unsigned attributes as Integer attributes, Quantity attributes as Double attributes with units, Unit attributes as String attributes.

std::ostream & toJSON ( const std::vector< Attribute > &  attributes,
std::ostream &  os 
)
related

Puts attributes out to os in a flat json format.

Discards uuid and version_uuid information. Recasts Unsigned attributes as Integer attributes, Quantity attributes as Double attributes with units, Unit attributes as String attributes.

std::string toJSON ( const std::vector< Attribute > &  attributes)
related

Returns attributes as a string in a flat json format.

Discards uuid and version_uuid information. Recasts Unsigned attributes as Integer attributes, Quantity attributes as Double attributes with units, Unit attributes as String attributes.

std::string toJSONWithoutMetadata ( const std::vector< Attribute > &  attributes)
related

Returns attributes as a string in a flat json format.

Discards uuid and version_uuid information. Recasts Unsigned attributes as Integer attributes, Quantity attributes as Double attributes with units, Unit attributes as String attributes. Does not print metadata.

std::vector< Attribute > toVectorOfAttribute ( const openstudio::path &  pathToJson)
related

Deserializes the flat attribute json format.

std::vector< Attribute > toVectorOfAttribute ( std::istream &  json)
related

Deserializes the flat attribute json format.

std::vector< Attribute > toVectorOfAttribute ( const std::string &  json)
related

Deserializes the flat attribute json format.