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

#include <WorkspaceObject.hpp>

+ Inheritance diagram for openstudio::WorkspaceObject:

Public Member Functions

Constructors and Destructors
virtual ~WorkspaceObject () override=default
 
 WorkspaceObject (const WorkspaceObject &other)=default
 
 WorkspaceObject (WorkspaceObject &&other)=default
 
WorkspaceObjectoperator= (const WorkspaceObject &)=default
 
WorkspaceObjectoperator= (WorkspaceObject &&)=default
 
std::vector
< openstudio::IdfObject
remove ()
 Removes the object from the Workspace. More...
 
Getters
Workspace workspace () const
 Return the Workspace that contains this WorkspaceObject. More...
 
boost::optional< WorkspaceObjectgetTarget (unsigned index) const
 Returns the object pointed to by field index, if it exists. More...
 
std::vector< WorkspaceObjecttargets () const
 Returns all objects pointed to by this object. More...
 
std::vector< unsigned > getSourceIndices (const Handle &targetHandle) const
 Returns the index of the field in this object that points to targetHandle, if possible. More...
 
std::vector< WorkspaceObjectsources () const
 Returns all objects that point to this object, filtering for duplicate objects. More...
 
std::vector< WorkspaceObjectgetSources (IddObjectType type) const
 Returns all objects of type that point to this object, filtering for duplicate objects. More...
 
Setters
bool setPointer (unsigned index, const Handle &targetHandle)
 Sets the pointer at field index to targetHandle, if possible. More...
 
Queries
bool operator< (const WorkspaceObject &right) const
 
bool initialized () const
 
unsigned numSources () const
 Returns the number of objects that point to this object. More...
 
bool isSource () const
 Returns true if this object points to another object. More...
 
bool canBeSource () const
 Returns true if this object can point to another object. More...
 
bool canBeSource (unsigned index, const std::vector< std::string > &refLists=std::vector< std::string >()) const
 Returns true if field index can be a source field. More...
 
bool isTarget () const
 Returns true if another object points to this object. More...
 
std::vector< std::string > canBeTarget () const
 Returns the reference lists of which this object is a member, if this object has a name. More...
 
bool objectListFieldsEqual (const WorkspaceObject &other) const
 Checks for equality of objectListFields(). More...
 
bool objectListFieldsNonConflicting (const WorkspaceObject &other) const
 Returns true if for all objectListFields() that for both objects are non-empty, the values are equal (using the same criteria as objectListFieldsEqual). More...
 
Serialization
IdfObject idfObject ()
 Returns an equivalent IdfObject, naming target objects if necessary. More...
 
IdfObject idfObject () const
 Returns an equivalent IdfObject, leaving unnamed target objects unnamed. More...
 
- Public Member Functions inherited from openstudio::IdfObject
 IdfObject (IddObjectType type, bool fastName=false)
 Constructor from type. More...
 
 IdfObject (const IddObject &, bool fastName=false)
 Constructor from iddObject. More...
 
virtual ~IdfObject ()=default
 
 IdfObject (const IdfObject &other)
 Copy constructor. More...
 
 IdfObject (IdfObject &&other) noexcept
 
IdfObjectoperator= (const IdfObject &other)
 
IdfObjectoperator= (IdfObject &&other) noexcept
 
IdfObject clone (bool keepHandle=false) const
 Creates a deep copy of this object. More...
 
Handle handle () const
 Returns this object's handle, which is only valid in the containing Workspace. More...
 
IddObject iddObject () const
 Get this object's IddObject. More...
 
std::string comment () const
 Returns the comment block associated with the object. More...
 
boost::optional< std::string > fieldComment (unsigned index, bool returnDefault=false) const
 Returns the comment associated with field index, if one exists. More...
 
boost::optional< std::string > name (bool returnDefault=false) const
 Get the name of the object, if it exists. More...
 
std::string nameString (bool returnDefault=false) const
 Returns the name if set or returns an empty string. More...
 
std::string briefDescription () const
 Get a brief description of this object. More...
 
bool isEmpty (unsigned index) const
 Returns true if the field is empty. More...
 
boost::optional< std::string > getString (unsigned index, bool returnDefault=false, bool returnUninitializedEmpty=false) const
 Get the value of field index, if index < numFields(). More...
 
boost::optional< std::string > getField (unsigned index, bool returnDefault=false) const
 Like getString except for reference fields getString will return the name of the referenced object. More...
 
boost::optional< double > getDouble (unsigned index, bool returnDefault=false) const
 Get the value of the field at index, converted to double, if possible. More...
 
OSOptionalQuantity getQuantity (unsigned index, bool returnDefault=false, bool returnIP=false) const
 Returns the Quantity at index, if possible. More...
 
boost::optional< unsigned > getUnsigned (unsigned index, bool returnDefault=false) const
 Get the value of the field at index, converted to unsigned, if possible. More...
 
boost::optional< intgetInt (unsigned index, bool returnDefault=false) const
 Get value of the field at index, converted to int, if possible. More...
 
IdfExtensibleGroup getExtensibleGroup (unsigned groupIndex) const
 Returns the IdfExtensibleGroup at groupIndex, if it exists. More...
 
std::vector< IdfExtensibleGroupextensibleGroups () const
 Returns this object's IdfExtensibleGroups. More...
 
void setComment (const std::string &msg)
 Sets the comment block associated with the object. More...
 
bool setFieldComment (unsigned index, const std::string &cmnt)
 Sets the comment associated with field index, if that field exists. More...
 
boost::optional< std::string > setName (const std::string &newName)
 Sets the name field if it exists, returning the actual name string set. More...
 
boost::optional< std::string > createName (bool overwrite=true)
 Sets the name field to a new, unique name, if the name field exists and (is empty or overwrite == true). More...
 
bool setString (unsigned index, const std::string &value)
 Sets the field at index to value, if possible. More...
 
bool setDouble (unsigned index, double value)
 Sets the field at index to value, if possible. More...
 
bool setQuantity (unsigned index, const Quantity &q)
 Sets the field at index to q, if possible. More...
 
bool setUnsigned (unsigned index, unsigned value)
 Sets the field at index to value, if possible. More...
 
bool setInt (unsigned index, int value)
 Sets the field at index to value, if possible. More...
 
IdfExtensibleGroup pushExtensibleGroup ()
 Pushes a new extensible group onto the object, if possible. More...
 
IdfExtensibleGroup pushExtensibleGroup (const std::vector< std::string > &values)
 Pushes a new extensible group onto the object, if possible. More...
 
IdfExtensibleGroup insertExtensibleGroup (unsigned groupIndex)
 Inserts a new extensible group at groupIndex, if possible. More...
 
IdfExtensibleGroup insertExtensibleGroup (unsigned groupIndex, const std::vector< std::string > &values)
 Inserts a new extensible group at groupIndex, if possible. More...
 
std::vector< std::string > popExtensibleGroup ()
 Pops the final extensible group from the object, if possible. More...
 
std::vector< std::string > eraseExtensibleGroup (unsigned groupIndex)
 Erases the extensible group at groupIndex, if possible. More...
 
std::vector< std::vector
< std::string > > 
clearExtensibleGroups ()
 Pops all IdfExtensibleGroups from the object, if possible. More...
 
unsigned numFields () const
 Returns the current number of fields (including extensible groups) in the object. More...
 
unsigned numNonextensibleFields () const
 Returns the current number of non-extensible fields in the object. More...
 
unsigned minFields () const
 Returns the minimum number of fields an object of this type must have to be valid. More...
 
boost::optional< unsigned > maxFields () const
 Returns the maximum number of fields an object of this type can have and still be valid. More...
 
unsigned numExtensibleGroups () const
 Returns the number of extensible groups in the object. More...
 
unsigned minExtensibleGroups () const
 Returns the minimum number of IdfExtensibleGroups an object of this type must have to be valid. More...
 
boost::optional< unsigned > maxExtensibleGroups () const
 Returns the maximum number of IdfExtensibleGroups an object of this type must have to be valid. More...
 
bool isObjectListField (unsigned index) const
 Returns true if index is in objectListFields(). More...
 
std::vector< unsigned > objectListFields () const
 Returns the indices of all fields that can point to other objects. More...
 
bool isDataField (unsigned index) const
 Returns true if index is in dataFields(). More...
 
std::vector< unsigned > dataFields () const
 Returns the indices of all fields that are not managedObjectListFields(). More...
 
std::vector< unsigned > requiredFields () const
 Returns the indices of all fields that are required, as defined by the IddObject. More...
 
bool isValid (StrictnessLevel level, bool checkNames=false) const
 Returns true if this IdfObject is valid, that is, has no errors at or below level. More...
 
ValidityReport validityReport (StrictnessLevel level, bool checkNames=false) const
 Returns a ValidityReport for this IdfObject containing all errors at or below level. More...
 
bool dataFieldsEqual (const IdfObject &other) const
 Checks for equality of data (non-managedObjectList) fields. More...
 
bool objectListFieldsEqual (const IdfObject &other) const
 Checks for equality of objectListFields(). More...
 
bool objectListFieldsNonConflicting (const IdfObject &other) const
 Returns true if for all managedObjectListFields() that for both objects are non-empty, the values are equal (using the same criteria as objectListFieldsEqual). More...
 
bool operator== (const IdfObject &other) const
 Equality comparator for IdfObjects. More...
 
bool operator!= (const IdfObject &other) const
 Negation of operator==. More...
 
template<typename T >
cast () const
 cast to type T, can throw std::bad_cast More...
 
template<typename T >
boost::optional< T > optionalCast () const
 cast to optional of type T More...
 
std::ostream & print (std::ostream &os) const
 Serialize this object to os as Idf text. More...
 
std::ostream & printName (std::ostream &os, bool hasFields=true) const
 Serialize just the preceding comments and name of this IdfObject in the format used by full object print. More...
 
std::ostream & printField (std::ostream &os, unsigned index, bool isLastField=false) const
 Serialize field index in the format used by full object print. More...
 

Protected Types

using ImplType = detail::WorkspaceObject_Impl
 
- Protected Types inherited from openstudio::IdfObject
using ImplType = detail::IdfObject_Impl
 

Protected Member Functions

 WorkspaceObject (std::shared_ptr< detail::WorkspaceObject_Impl > impl)
 
- Protected Member Functions inherited from openstudio::IdfObject
 IdfObject (std::shared_ptr< detail::IdfObject_Impl > impl)
 Protected constructor from impl. More...
 

Related Functions

(Note that these are not member functions.)

std::ostream & operator<< (std::ostream &os, const WorkspaceObject &workspaceObject)
 
using OptionalWorkspaceObject = boost::optional< WorkspaceObject >
 
using WorkspaceObjectVector = std::vector< WorkspaceObject >
 

Additional Inherited Members

- Static Public Member Functions inherited from openstudio::IdfObject
static boost::optional< IdfObjectload (const std::string &text)
 Constructor from text. More...
 
static boost::optional< IdfObjectload (const std::string &text, const IddObject &iddObject)
 Constructor from text and an explicit iddObject. More...
 
static int printedFieldSpace ()
 Returns the width, in characters, of the default amount of space given to field data during printing. More...
 

Detailed Description

WorkspaceObject holds and manipulates data objects in Energyplus IDF format in the context of a Workspace.

Over and above IdfObject, WorkspaceObject maintains ObjectListType fields as pointers (possibly null) to other WorkspaceObjects in the same Workspace, and only commits changes that maintain the validity of its Workspace at the current StrictnessLevel (typically Draft, moving to Final right before simulation).

Member Typedef Documentation

using openstudio::WorkspaceObject::ImplType = detail::WorkspaceObject_Impl
protected

Constructor & Destructor Documentation

virtual openstudio::WorkspaceObject::~WorkspaceObject ( )
overridevirtualdefault
openstudio::WorkspaceObject::WorkspaceObject ( const WorkspaceObject other)
default
openstudio::WorkspaceObject::WorkspaceObject ( WorkspaceObject &&  other)
default
openstudio::WorkspaceObject::WorkspaceObject ( std::shared_ptr< detail::WorkspaceObject_Impl >  impl)
protected

Member Function Documentation

bool openstudio::WorkspaceObject::canBeSource ( ) const

Returns true if this object can point to another object.

To qualify, there must be at least one object-list field.

bool openstudio::WorkspaceObject::canBeSource ( unsigned  index,
const std::vector< std::string > &  refLists = std::vector< std::string >() 
) const

Returns true if field index can be a source field.

If no refLists are specified, then this call is equivalent to iddObject().getField(index)->isObjectListField(). If a non-empty vector of refLists is specified, then true is only returned if there is a match between field index's object lists and the referencesLists argument.

std::vector<std::string> openstudio::WorkspaceObject::canBeTarget ( ) const

Returns the reference lists of which this object is a member, if this object has a name.

std::vector<unsigned> openstudio::WorkspaceObject::getSourceIndices ( const Handle targetHandle) const

Returns the index of the field in this object that points to targetHandle, if possible.

std::vector<WorkspaceObject> openstudio::WorkspaceObject::getSources ( IddObjectType  type) const

Returns all objects of type that point to this object, filtering for duplicate objects.

boost::optional<WorkspaceObject> openstudio::WorkspaceObject::getTarget ( unsigned  index) const

Returns the object pointed to by field index, if it exists.

IdfObject openstudio::WorkspaceObject::idfObject ( )

Returns an equivalent IdfObject, naming target objects if necessary.

All data is cloned. If the objects have handle fields (as in the OpenStudio IDD), pointers to other objects are printed as handles; otherwise pointers are printed as names.

IdfObject openstudio::WorkspaceObject::idfObject ( ) const

Returns an equivalent IdfObject, leaving unnamed target objects unnamed.

All data is cloned. If the objects have handle fields (as in the OpenStudio IDD), pointers to other objects are printed as handles; otherwise pointers are printed as names.

bool openstudio::WorkspaceObject::initialized ( ) const
bool openstudio::WorkspaceObject::isSource ( ) const

Returns true if this object points to another object.

To qualify, there must be at least one pointer field holding a non-null pointer.

bool openstudio::WorkspaceObject::isTarget ( ) const

Returns true if another object points to this object.

unsigned openstudio::WorkspaceObject::numSources ( ) const

Returns the number of objects that point to this object.

bool openstudio::WorkspaceObject::objectListFieldsEqual ( const WorkspaceObject other) const

Checks for equality of objectListFields().

Prerequisite: iddObject()s must be equal. Looks for object equality of targets if same workspace(), otherwise, looks for data field equality of targets.

bool openstudio::WorkspaceObject::objectListFieldsNonConflicting ( const WorkspaceObject other) const

Returns true if for all objectListFields() that for both objects are non-empty, the values are equal (using the same criteria as objectListFieldsEqual).

Prerequisite: iddObject()s must be equal.

bool openstudio::WorkspaceObject::operator< ( const WorkspaceObject right) const
WorkspaceObject& openstudio::WorkspaceObject::operator= ( const WorkspaceObject )
default
WorkspaceObject& openstudio::WorkspaceObject::operator= ( WorkspaceObject &&  )
default
std::vector<openstudio::IdfObject> openstudio::WorkspaceObject::remove ( )

Removes the object from the Workspace.

Returns an IdfObjectVector of all removed object(s).

bool openstudio::WorkspaceObject::setPointer ( unsigned  index,
const Handle targetHandle 
)

Sets the pointer at field index to targetHandle, if possible.

The field must be of object-list type, and targetHandle must be valid (null or in the containing Workspace, and if the strictness is greater than enums::None, must correspond to an object of a proper type).

std::vector<WorkspaceObject> openstudio::WorkspaceObject::sources ( ) const

Returns all objects that point to this object, filtering for duplicate objects.

std::vector<WorkspaceObject> openstudio::WorkspaceObject::targets ( ) const

Returns all objects pointed to by this object.

Workspace openstudio::WorkspaceObject::workspace ( ) const

Return the Workspace that contains this WorkspaceObject.

Friends And Related Function Documentation

std::ostream & operator<< ( std::ostream &  os,
const WorkspaceObject workspaceObject 
)
related

Outputs WorkspaceObject as (IDF) text.

using OptionalWorkspaceObject = boost::optional<WorkspaceObject>
related
using WorkspaceObjectVector = std::vector<WorkspaceObject>
related