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

Related Symbols

(Note that these are not member symbols.)

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

Serialization

using ImplType = detail::WorkspaceObject_Impl
 
IdfObject idfObject ()
 Returns an equivalent IdfObject, naming target objects if necessary.
 
IdfObject idfObject () const
 Returns an equivalent IdfObject, leaving unnamed target objects unnamed.
 
 WorkspaceObject (std::shared_ptr< detail::WorkspaceObject_Impl > impl)
 

Additional Inherited Members

- Static Public Member Functions inherited from openstudio::IdfObject
static boost::optional< IdfObjectload (const std::string &text)
 Constructor from text.
 
static boost::optional< IdfObjectload (const std::string &text, const IddObject &iddObject)
 Constructor from text and an explicit iddObject.
 
static int printedFieldSpace ()
 Returns the width, in characters, of the default amount of space given to field data during printing.
 
- Protected Types inherited from openstudio::IdfObject
using ImplType = detail::IdfObject_Impl
 
- Protected Member Functions inherited from openstudio::IdfObject
 IdfObject (std::shared_ptr< detail::IdfObject_Impl > impl)
 Protected constructor from impl.
 

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

◆ ImplType

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

Constructor & Destructor Documentation

◆ ~WorkspaceObject()

virtual openstudio::WorkspaceObject::~WorkspaceObject ( )
overridevirtualdefault

◆ WorkspaceObject() [1/3]

openstudio::WorkspaceObject::WorkspaceObject ( const WorkspaceObject & other)
default

◆ WorkspaceObject() [2/3]

openstudio::WorkspaceObject::WorkspaceObject ( WorkspaceObject && other)
default

◆ WorkspaceObject() [3/3]

openstudio::WorkspaceObject::WorkspaceObject ( std::shared_ptr< detail::WorkspaceObject_Impl > impl)
protected

Member Function Documentation

◆ canBeSource() [1/2]

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.

◆ canBeSource() [2/2]

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.

◆ canBeTarget()

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.

◆ getSourceIndices()

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.

◆ getSources()

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

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

◆ getTarget()

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

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

◆ idfObject() [1/2]

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() [2/2]

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.

◆ initialized()

bool openstudio::WorkspaceObject::initialized ( ) const

◆ isSource()

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.

◆ isTarget()

bool openstudio::WorkspaceObject::isTarget ( ) const

Returns true if another object points to this object.

◆ numSources()

unsigned openstudio::WorkspaceObject::numSources ( ) const

Returns the number of objects that point to this object.

◆ objectListFieldsEqual()

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.

◆ objectListFieldsNonConflicting()

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.

◆ operator<()

bool openstudio::WorkspaceObject::operator< ( const WorkspaceObject & right) const

◆ operator=() [1/2]

WorkspaceObject & openstudio::WorkspaceObject::operator= ( const WorkspaceObject & )
default

◆ operator=() [2/2]

WorkspaceObject & openstudio::WorkspaceObject::operator= ( WorkspaceObject && )
default

◆ remove()

std::vector< openstudio::IdfObject > openstudio::WorkspaceObject::remove ( )

Removes the object from the Workspace.

Returns an IdfObjectVector of all removed object(s).

◆ setPointer()

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).

◆ sources()

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

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

◆ targets()

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

Returns all objects pointed to by this object.

◆ workspace()

Workspace openstudio::WorkspaceObject::workspace ( ) const

Return the Workspace that contains this WorkspaceObject.

Friends And Related Symbol Documentation

◆ operator<<()

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

Outputs WorkspaceObject as (IDF) text.

◆ OptionalWorkspaceObject

using OptionalWorkspaceObject = boost::optional<WorkspaceObject>
related

◆ WorkspaceObjectVector

using WorkspaceObjectVector = std::vector<WorkspaceObject>
related