The SKIRT project
advanced radiative transfer for astrophysics
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
SchemaDef Class Referencefinal

#include <SchemaDef.hpp>

Public Member Functions

 SchemaDef (const SchemaDef &)=delete
 
 SchemaDef (string filePath)
 
 SchemaDef (string name, string title, string version, string extension, string root, string type, string format, string url)
 
TypeDefaddTypeDef (string name, string base, string title, TypeDef::Instantiator instantiator=nullptr)
 
string allowed (string type) const
 
string allowedAndDisplayed (string type) const
 
vector< string > ascendants (string type) const
 
std::unique_ptr< ItemcreateItem (string type) const
 
std::unique_ptr< PropertyHandlercreatePropertyHandler (Item *item, string property, NameManager *nameMgr) const
 
string definingType (string type, string property) const
 
vector< string > descendants (string type) const
 
bool has (string qty) const
 
bool has (string qty, string unit) const
 
bool hasMultipleUnitSystems () const
 
double in (string qty, string unit, double value) const
 
bool inherits (string childType, string parentType) const
 
void loadUnitDef (const UnitDef &unitDef)
 
SchemaDefoperator= (const SchemaDef &)=delete
 
double out (string qty, string unit, double value) const
 
vector< string > properties (string type) const
 
string propertyTitle (string type, string property) const
 
void save (string filePath, string producer=string()) const
 
string schemaExtension () const
 
string schemaFormat () const
 
string schemaName () const
 
string schemaProducer () const
 
string schemaRoot () const
 
string schemaTitle () const
 
string schemaType () const
 
string schemaUrl () const
 
string schemaVersion () const
 
string title (string type) const
 
vector< string > titles (const vector< string > &types) const
 
vector< string > toBeInserted (string type) const
 
string unit (string qty, string unitSystem, string unitStyle) const
 
string unitSystemBase () const
 

Static Public Member Functions

static string getSchemaTitle (string filePath)
 
static bool isCompatible (string schemaFilePath, string dataFilePath)
 

Private Member Functions

const PropertyDefpropertyDef (string type, string property) const
 
const TypeDeftypeDef (string type) const
 

Private Attributes

std::map< string, TypeDef_allTypes
 
vector< string > _concreteTypes
 
string _extension
 
string _format
 
string _name
 
string _producer
 
string _root
 
string _title
 
string _type
 
UnitDef _unitDef
 
string _url
 
string _version
 

Detailed Description

The SchemaDef class represents a SMILE schema definition. It offers facilities for loading a SMILE schema from file or through calling the relevant "add" functions, and for querying the information in the loaded schema in various ways.

Constructor & Destructor Documentation

◆ SchemaDef() [1/3]

SchemaDef::SchemaDef ( string  filePath)

This constructor loads a particular SMILE schema from the SMILE XML file with the specified path. When an error occurs while opening, parsing or interpreting the XML data stream, the constructor throws a FatalError with an appropriate error message.

◆ SchemaDef() [2/3]

SchemaDef::SchemaDef ( string  name,
string  title,
string  version,
string  extension,
string  root,
string  type,
string  format,
string  url 
)

This constructor creates an empty SMILE schema with the specified basic properties. The type, property and and unit information for the schema must be added by calling the appropriate "add" functions. The constructor arguments specify, in order of occurrence:

  • name: a short name for this schema
  • title: a description of the type of datasets described by this schema
  • version: the version of this schema definition
  • extension: the filename extension for datasets described by this schema
  • root: the name of the root element in datasets described by this schema
  • type: the type of the top-level item in datasets described by this schema
  • format: the version of the described data format (specified on the root element)
  • url: a URL pointing to information on the Web for this schema (or the empty string if not available)

◆ SchemaDef() [3/3]

SchemaDef::SchemaDef ( const SchemaDef )
delete

The copy constructor is deleted. SchemaDef instances can't be copied or moved because of the PropertyDef instances they contain.

Member Function Documentation

◆ addTypeDef()

TypeDef & SchemaDef::addTypeDef ( string  name,
string  base,
string  title,
TypeDef::Instantiator  instantiator = nullptr 
)

This function creates an empty type definition, adds it to the schema definition, and returns a writable reference to it. The first three arguments specify the name of the type, the name of its base type, and the description of the type. The last argument specifies the function that will be used to create instances of this type. It should be provided for all concrete types, and should be left to the default (a null pointer) for abstract types. The type name, the base type name, the description and the concrete/abstract flag are set by this function. All other information in the type definition, including any property definitions, must be completed or added by calling the type definition's setter functions. This function throws a fatal error if the schema definition already contains a type with the specified name (to keep the function from being abused to retrieve a writable reference to an existing type definition).

◆ allowed()

string SchemaDef::allowed ( string  type) const

Returns a Boolean expression that, when evaluated against the current global and local name sets, will determine whether the specified type is allowed. To obtain this result, the Boolean expressions in the "allowedIf" attribute values for the specified type and for any of its base types, recursively, are concatenated with the AND operator into a single Boolean expression. The function throws an error if the specified type is not defined in the schema.

◆ allowedAndDisplayed()

string SchemaDef::allowedAndDisplayed ( string  type) const

Returns a Boolean expression that, when evaluated against the current global and local name sets, will determine whether the specified type is allowed and displayed. To obtain this result, the Boolean expressions in the "allowedIf" and "displayedIf" attribute values for the specified type and for any of its base types, recursively, are concatenated with the AND operator into a single Boolean expression. The function throws an error if the specified type is not defined in the schema.

◆ ascendants()

vector< string > SchemaDef::ascendants ( string  type) const

Returns a list of the types from which the specified type inherits, directly or indirectly, starting with the type itself up to and including the root type of the hierarchy. The list includes both concrete and abstract types. The function throws an error if the specified type is not defined in the schema.

◆ createItem()

std::unique_ptr< Item > SchemaDef::createItem ( string  type) const

Creates a new SMILE data item of the specified type. Ownership of the new object is passed to the caller through a unique pointer. This function throws an error if the specified type is not defined in the schema, or if the type is an abstract type.

◆ createPropertyHandler()

std::unique_ptr< PropertyHandler > SchemaDef::createPropertyHandler ( Item item,
string  property,
NameManager nameMgr 
) const

Creates a new property handler for the specified property in the specified SMILE data item, and returns a unique pointer to this new instance. The third argument, a pointer to the name manager used for the current dataset, is passed to the property handler so that it can access the global and local name sets for evaluating Boolean expressions.

The returned handler is of a PropertyHandler subclass appropriate for the property type. Because it is guarded by a unique pointer, the handler is automatically deleted when the return value goes out of scope. This function throws an error if the specified item does not have a property with the specified name.

◆ definingType()

string SchemaDef::definingType ( string  type,
string  property 
) const

Returns the name of the particular (base) type in which the specified property is defined for the specified (concrete) type. If the specified property is not defined in the specified type or in one of its base types, the function throws a fatal error.

◆ descendants()

vector< string > SchemaDef::descendants ( string  type) const

Returns a list of concrete types that inherit the specified type, in the order listed in the schema definition. The function throws an error if the specified type is not defined in the schema.

◆ getSchemaTitle()

static string SchemaDef::getSchemaTitle ( string  filePath)
static

This static function returns the value of the 'title' attribute on the Schema element in the SMILE XML file with the specified file path, or the empty string if an error occurs.

◆ has() [1/2]

bool SchemaDef::has ( string  qty) const

This function returns returns true if the specified physical quantity is provided in the schema definition, and false if it is not. The name of the physical quantity is case sensitive and should not contain any spaces.

◆ has() [2/2]

bool SchemaDef::has ( string  qty,
string  unit 
) const

This function returns true if the specified combination of physical quantity and unit or unit system is provided in the schema definition, and false if not. The name of the physical quantity must always be specified. The unit can be specified either directly, or indirectly by providing the name of a unit system. In the latter case, the function uses the default units for the specified quantity in the specified unit system. All names (physical quantity, unit system, and units) are case sensitive and should not contain any spaces.

◆ hasMultipleUnitSystems()

bool SchemaDef::hasMultipleUnitSystems ( ) const

This function returns true if two or more unit systems are provided in the schema definition. Otherwise it returns false.

◆ in()

double SchemaDef::in ( string  qty,
string  unit,
double  value 
) const

This function converts a physical value from the specified units to internal program units. Refer to the has() function for a description of how to specify the physical quantity and unit. If the specified combination is not provided in the schema definition, the function throws an exception.

◆ inherits()

bool SchemaDef::inherits ( string  childType,
string  parentType 
) const

Returns true if the first type inherits the second. The function throws an error if the first type (the child type) is not defined in the schema.

◆ isCompatible()

static bool SchemaDef::isCompatible ( string  schemaFilePath,
string  dataFilePath 
)
static

This static function determines whether the SMILE dataset with the specified file path is compatible with the SMILE schema defined in the SMILE XML file with the specified file path, by examining the root and top-level elements in both XML files. The function returns true if the dataset is compatible with the schema, and false if not or if an error occurs.

◆ loadUnitDef()

void SchemaDef::loadUnitDef ( const UnitDef unitDef)

This function copies the contents of the specified unit definition into the schema definition. Any pre-existing unit and unit system information is discarded.

◆ operator=()

SchemaDef & SchemaDef::operator= ( const SchemaDef )
delete

The assignment operator is deleted. SchemaDef instances can't be copied or moved because of the PropertyDef instances they contain.

◆ out()

double SchemaDef::out ( string  qty,
string  unit,
double  value 
) const

This function converts a physical value from internal program units to the specified units. Refer to the has() function for a description of how to specify the physical quantity and unit. If the specified combination is not provided in the schema definition, the function throws an exception.

◆ properties()

vector< string > SchemaDef::properties ( string  type) const

Returns the names of all properties for the specified type, including inherited properties for all direct and indirect base types. By default, base type properties are listed first, and for each type, properties are listed in the order of the schema definition. However, base types can specify that subtype properties must be inserted before a given property rather than being added at the end of the list.

◆ propertyDef()

const PropertyDef & SchemaDef::propertyDef ( string  type,
string  property 
) const
private

Returns a reference to the property definition for the specified type and property, or throws an error if the specified type and property combination is not defined in the schema.

◆ propertyTitle()

string SchemaDef::propertyTitle ( string  type,
string  property 
) const

Returns the title (used for display to a user) associated with the specified property of the specified type. The function throws an error if the specified property and type combination is not defined in the schema.

◆ save()

void SchemaDef::save ( string  filePath,
string  producer = string() 
) const

This function saves the SMILE schema to the SMILE XML file with the specified path. The optional last argument specifies a producer identification string to be included as an attribute on the root element. When an error occurs while opening the file or while writing the XML data stream, the function throws a FatalError with an appropriate error message.

◆ schemaExtension()

string SchemaDef::schemaExtension ( ) const

Returns the filename extension for datasets described by this schema.

◆ schemaFormat()

string SchemaDef::schemaFormat ( ) const

Returns the version of the described data format (specified on the root element in data sets described by this schema).

◆ schemaName()

string SchemaDef::schemaName ( ) const

Returns a short name for this schema.

◆ schemaProducer()

string SchemaDef::schemaProducer ( ) const

Returns a description of the producer of the file from which this schema was loaded.

◆ schemaRoot()

string SchemaDef::schemaRoot ( ) const

Returns the name of the root element in datasets described by this schema.

◆ schemaTitle()

string SchemaDef::schemaTitle ( ) const

Returns a description of the type of datasets described by this schema.

◆ schemaType()

string SchemaDef::schemaType ( ) const

Returns the type of the top-level item in datasets described by this schema.

◆ schemaUrl()

string SchemaDef::schemaUrl ( ) const

Returns a URL pointing to information on the Web for this schema.

◆ schemaVersion()

string SchemaDef::schemaVersion ( ) const

Returns the version of this schema definition.

◆ title()

string SchemaDef::title ( string  type) const

Returns the title (used for display to a user) associated with the specified type. The function throws an error if the specified type is not defined in the schema.

◆ titles()

vector< string > SchemaDef::titles ( const vector< string > &  types) const

Returns the titles (used for display to a user) associated with the specified types, in the same order.

◆ toBeInserted()

vector< string > SchemaDef::toBeInserted ( string  type) const

Returns a list of conditional value expressions that, when evaluated against the current global and local name sets, will provide the names that need to be inserted when the specified type is entered into a dataset. The list includes the conditional value expressions given as "insert" attribute values for the specified type and for any of its base types, recursively. Empty "insert" attribute values are not included, so the returned list may be empty. The function throws an error if the specified type is not defined in the schema.

◆ typeDef()

const TypeDef & SchemaDef::typeDef ( string  type) const
private

Returns a reference to the type definition for the specified type, or throws an error if the specified type is not defined in the schema.

◆ unit()

string SchemaDef::unit ( string  qty,
string  unitSystem,
string  unitStyle 
) const

This function returns the name of the default unit listed in the schema definition for the specified physical quantity in the specified unit system. If the specified unit style is nonempty, the function first prefixes the quantity name with the unit style string and attempts to locate the default value for this embellished quantity name. If this fails, the function tries again with the regular quantity name.

The physical quantity, unit system, and unit style name are case sensitive and should not contain any spaces. If the specified combination of physical quantity (embellished or not) and unit system is not present in the unit definition, the function throws an exception.

◆ unitSystemBase()

string SchemaDef::unitSystemBase ( ) const

If the schema definition does not provide a unit system, this function throws an error. If the schema definition provides a single unit system, the function returns the name of that unit system. If the schema definition provides two or more unit systems, the function returns the name of the common base type for the types corresponding to each of the unit systems. If not all of the unit systems have corresponding types, or if there is no common base type, the function throws an error. The common base type is defined as a type with a set of concrete descendents that exactly matches the set of unit systems.


The documentation for this class was generated from the following file: