OpenStudioCore:utilities
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Protected Member Functions | List of all members
openstudio::IdfFile Class Reference

#include <IdfFile.hpp>

Public Member Functions

Constructors
 IdfFile (IddFileType iddFileType=IddFileType("OpenStudio"))
 Default constructor with optional IddFileType argument (default is IddFileType::OpenStudio). More...
 
 IdfFile (const IddFile &iddFile)
 Construct from iddFile. More...
 
Getters
std::string header () const
 Returns the file header, that is, the comment block at the top of the file. More...
 
VersionString version () const
 Returns the version of this model, as determined by the IddFile header. More...
 
IddFile iddFile () const
 Returns the underlying IddFile (the schema for this IdfFile). More...
 
IddFileType iddFileType () const
 Returns the underlying IddFile's IddFileType. More...
 
boost::optional< IdfObjectversionObject () const
 Returns the version IdfObject in this file, if it exists and is unique. More...
 
boost::optional< IdfObjectgetObject (unsigned index) const
 Returns the object at index. More...
 
boost::optional< IdfObjectgetObject (const Handle &handle) const
 Returns the object with .handle() == handle, if such an object exists in this file. More...
 
std::vector< IdfObjectobjects () const
 Returns all the objects in this file, excluding versionObject(). More...
 
std::vector< IdfObjectgetObjectsByType (IddObjectType objectType) const
 Returns all objects of objectType (e.g. More...
 
std::vector< IdfObjectgetObjectsByType (const IddObject &objectType) const
 Returns all objects in this file for which .iddObject() == objectType. More...
 
std::vector< IdfObjectgetObjectsByName (const std::string &name) const
 Returns all objects named name (case insensitive). More...
 
Setters
void setHeader (const std::string &header)
 Set the header for this file. More...
 
void addObject (const IdfObject &object)
 Append object to the end of this file. More...
 
void addObjects (const std::vector< IdfObject > &objects)
 Append objects to the end of this file. More...
 
void insertObjectByIddObjectType (const IdfObject &object)
 Insert object immediately before the first object in this file whose IddObjectType value is greater than object's. More...
 
bool removeObject (const IdfObject &object)
 Removes object from this file if it is in this file. More...
 
int removeObjects (const std::vector< IdfObject > &objects)
 Attempts to remove each element of objects from this file, returning the number of successfully removed objects. More...
 
Queries
bool empty () const
 Returns true if there is no header and no objects. More...
 
unsigned numObjects () const
 Returns the number of non-version objects in this file. More...
 
unsigned numObjectsOfType (IddObjectType objectType) const
 Returns the number of objects of objectType in this file. More...
 
unsigned numObjectsOfType (const IddObject &objectType) const
 Returns the number of objects of objectType in this file. More...
 
bool isValid (StrictnessLevel level) const
 Returns true if this IdfFile is valid, that is, has no DataErrors at or below level. More...
 
ValidityReport validityReport (StrictnessLevel level) const
 Returns a ValidityReport for this IdfFile containing all DataErrors at or below level. More...
 

Protected Member Functions

IddFileAndFactoryWrapper iddFileAndFactoryWrapper () const
 
void setIddFileAndFactoryWrapper (const IddFileAndFactoryWrapper &iddFileAndFactoryWrapper)
 

Serialization

std::ostream & print (std::ostream &os) const
 Print this file to std::ostream os. More...
 
bool save (const openstudio::path &p, bool overwrite=false)
 Save this file to path p. More...
 
static boost::optional< IdfFileload (std::istream &is, const IddFileType &iddFileType, ProgressBar *progressBar=nullptr)
 Load an IdfFile from std::istream using the IDD defined by IddFactory and iddFileType, if possible. More...
 
static boost::optional< IdfFileload (std::istream &is, const IddFile &iddFile, ProgressBar *progressBar=nullptr)
 Load an IdfFile from std::istream using iddFile, if possible. More...
 
static boost::optional< IdfFileload (const path &p, ProgressBar *progressBar=nullptr)
 Load an IdfFile from path using the IddFactory, and choosing iddFileType based on file extension, if possible. More...
 
static boost::optional< IdfFileload (const path &p, const IddFileType &iddFileType, ProgressBar *progressBar=nullptr)
 Load an IdfFile from path using the IddFactory and iddFileType, if possible. More...
 
static boost::optional< IdfFileload (const path &p, const IddFile &iddFile, ProgressBar *progressBar=nullptr)
 Load an IdfFile from path using iddFile, if possible. More...
 
static boost::optional
< VersionString
loadVersionOnly (std::istream &is)
 Quick load method that uses the IddFile::catchallIddFile and stops parsing once a version identifier is found. More...
 
static boost::optional
< VersionString
loadVersionOnly (const path &p)
 Quick load method that uses the IddFile::catchallIddFile and stops parsing once a version identifier is found. More...
 

Detailed Description

IdfFile provides parsing and printing of text files in EnergyPlus Input Data File (IDF) format.

This class can be used for ready-to-simulate EnergyPlus .idf files, OpenStudio .osm files, and partial idf/osm/osc files. This class expects to be constructed with the appropriate IddFile. An instance of the IddFileType enumeration class can be used to specify the latest EnergyPlus or OpenStudio IDD files. Previous versions of these IDD files, or IDD files of a different origin altogether, can be specified by explicitly calling IddFile::load, and then using that IddFile instance to load or construct an IdfFile.

IdfFile is not a shared object. It is composed of an ordered list of IdfObjects, each of which is a shared object.

Constructor & Destructor Documentation

openstudio::IdfFile::IdfFile ( IddFileType  iddFileType = IddFileType("OpenStudio"))

Default constructor with optional IddFileType argument (default is IddFileType::OpenStudio).

Initializes the file by adding a version IdfObject.

openstudio::IdfFile::IdfFile ( const IddFile iddFile)

Construct from iddFile.

Typically, iddFile is of IddFileType::UserCustom, that is, loaded from disk. Legacy OpenStudio IDD files back through Version 0.7.0 are available through the IddFactory. If possible, a version IdfObject is added.

Member Function Documentation

void openstudio::IdfFile::addObject ( const IdfObject object)

Append object to the end of this file.

void openstudio::IdfFile::addObjects ( const std::vector< IdfObject > &  objects)

Append objects to the end of this file.

bool openstudio::IdfFile::empty ( ) const

Returns true if there is no header and no objects.

(A versionObject does not count against emptiness.)

boost::optional<IdfObject> openstudio::IdfFile::getObject ( unsigned  index) const

Returns the object at index.

boost::optional<IdfObject> openstudio::IdfFile::getObject ( const Handle &  handle) const

Returns the object with .handle() == handle, if such an object exists in this file.

std::vector<IdfObject> openstudio::IdfFile::getObjectsByName ( const std::string &  name) const

Returns all objects named name (case insensitive).

std::vector<IdfObject> openstudio::IdfFile::getObjectsByType ( IddObjectType  objectType) const

Returns all objects of objectType (e.g.

IddObjectType("Zone"), IddObjectType("OS:Space")) in this file.

std::vector<IdfObject> openstudio::IdfFile::getObjectsByType ( const IddObject objectType) const

Returns all objects in this file for which .iddObject() == objectType.

std::string openstudio::IdfFile::header ( ) const

Returns the file header, that is, the comment block at the top of the file.

IddFile openstudio::IdfFile::iddFile ( ) const

Returns the underlying IddFile (the schema for this IdfFile).

IddFileAndFactoryWrapper openstudio::IdfFile::iddFileAndFactoryWrapper ( ) const
protected
IddFileType openstudio::IdfFile::iddFileType ( ) const

Returns the underlying IddFile's IddFileType.

void openstudio::IdfFile::insertObjectByIddObjectType ( const IdfObject object)

Insert object immediately before the first object in this file whose IddObjectType value is greater than object's.

bool openstudio::IdfFile::isValid ( StrictnessLevel  level) const

Returns true if this IdfFile is valid, that is, has no DataErrors at or below level.

static boost::optional<IdfFile> openstudio::IdfFile::load ( std::istream &  is,
const IddFileType iddFileType,
ProgressBar progressBar = nullptr 
)
static

Load an IdfFile from std::istream using the IDD defined by IddFactory and iddFileType, if possible.

static boost::optional<IdfFile> openstudio::IdfFile::load ( std::istream &  is,
const IddFile iddFile,
ProgressBar progressBar = nullptr 
)
static

Load an IdfFile from std::istream using iddFile, if possible.

static boost::optional<IdfFile> openstudio::IdfFile::load ( const path &  p,
ProgressBar progressBar = nullptr 
)
static

Load an IdfFile from path using the IddFactory, and choosing iddFileType based on file extension, if possible.

(IddFileType::OpenStudio if extension is modelFileExtension() or componentFileExtension(), IddFileType::EnergyPlus otherwise.)

static boost::optional<IdfFile> openstudio::IdfFile::load ( const path &  p,
const IddFileType iddFileType,
ProgressBar progressBar = nullptr 
)
static

Load an IdfFile from path using the IddFactory and iddFileType, if possible.

Will attempt to complete the path by tacking on .osm or .idf as appropriate.

static boost::optional<IdfFile> openstudio::IdfFile::load ( const path &  p,
const IddFile iddFile,
ProgressBar progressBar = nullptr 
)
static

Load an IdfFile from path using iddFile, if possible.

If no file extension is provided, will try "idf".

static boost::optional<VersionString> openstudio::IdfFile::loadVersionOnly ( std::istream &  is)
static

Quick load method that uses the IddFile::catchallIddFile and stops parsing once a version identifier is found.

Used to determine the appropriate IddFile to use for a full load.

static boost::optional<VersionString> openstudio::IdfFile::loadVersionOnly ( const path &  p)
static

Quick load method that uses the IddFile::catchallIddFile and stops parsing once a version identifier is found.

Used to determine the appropriate IddFile to use for a full load.

unsigned openstudio::IdfFile::numObjects ( ) const

Returns the number of non-version objects in this file.

unsigned openstudio::IdfFile::numObjectsOfType ( IddObjectType  objectType) const

Returns the number of objects of objectType in this file.

unsigned openstudio::IdfFile::numObjectsOfType ( const IddObject objectType) const

Returns the number of objects of objectType in this file.

std::vector<IdfObject> openstudio::IdfFile::objects ( ) const

Returns all the objects in this file, excluding versionObject().

std::ostream& openstudio::IdfFile::print ( std::ostream &  os) const

Print this file to std::ostream os.

bool openstudio::IdfFile::removeObject ( const IdfObject object)

Removes object from this file if it is in this file.

Otherwise returns false.

int openstudio::IdfFile::removeObjects ( const std::vector< IdfObject > &  objects)

Attempts to remove each element of objects from this file, returning the number of successfully removed objects.

bool openstudio::IdfFile::save ( const openstudio::path &  p,
bool  overwrite = false 
)

Save this file to path p.

Will construct the parent folder if necessary and if its parent folder already exists. Will only overwrite an existing file if overwrite==true. If no extension is provided will use modelFileExtension() for files using IddFileType::OpenStudio, and 'idf' otherwise. Returns true if the save operation is successful; false otherwise.

void openstudio::IdfFile::setHeader ( const std::string &  header)

Set the header for this file.

Will be printed as a comment block at the top of the file, before the objects. Automatically prefixes comment characters as needed.

void openstudio::IdfFile::setIddFileAndFactoryWrapper ( const IddFileAndFactoryWrapper iddFileAndFactoryWrapper)
protected
ValidityReport openstudio::IdfFile::validityReport ( StrictnessLevel  level) const

Returns a ValidityReport for this IdfFile containing all DataErrors at or below level.

VersionString openstudio::IdfFile::version ( ) const

Returns the version of this model, as determined by the IddFile header.

boost::optional<IdfObject> openstudio::IdfFile::versionObject ( ) const

Returns the version IdfObject in this file, if it exists and is unique.

Typically, the OS_ASSERT below will pass (but is not a trivial test).

IdfObject vo = versionObject().get();
OS_ASSERT(VersionString(vo.getString(vo.numFields() - 1,true).get()) == version());