From 650a0f0a2702c08435a5422864a537faf9419984 Mon Sep 17 00:00:00 2001 From: gereon Date: Sat, 12 Jan 2013 17:58:37 +0100 Subject: [PATCH] added documentation for AbstractModel and operator<< for ModelType --- src/models/AbstractModel.cpp | 26 +++++++++++++++++++ src/models/AbstractModel.h | 49 ++++++++++++++++++++++++------------ 2 files changed, 59 insertions(+), 16 deletions(-) create mode 100644 src/models/AbstractModel.cpp diff --git a/src/models/AbstractModel.cpp b/src/models/AbstractModel.cpp new file mode 100644 index 000000000..120115b05 --- /dev/null +++ b/src/models/AbstractModel.cpp @@ -0,0 +1,26 @@ +#include "src/models/AbstractModel.h" + +#include + +/*! + * This method will output the name of the model type or "Unknown". + * If something went terribly wrong, i.e. if type does not contain any value + * that is valid for a ModelType or some value of the enum was not + * implemented here, it will output "Invalid ModelType". + * + * @param os Output stream. + * @param type Model type. + * @return Output stream os. + */ +std::ostream& storm::models::operator<<(std::ostream& os, storm::models::ModelType const type) +{ + switch (type) { + case storm::models::Unknown: os << "Unknown"; break; + case storm::models::DTMC: os << "DTMC"; break; + case storm::models::CTMC: os << "CTMC"; break; + case storm::models::MDP: os << "MDP"; break; + case storm::models::CTMDP: os << "CTMDP"; break; + default: os << "Invalid ModelType"; break; + } + return os; +} diff --git a/src/models/AbstractModel.h b/src/models/AbstractModel.h index 1e7d6a32d..b3610ee09 100644 --- a/src/models/AbstractModel.h +++ b/src/models/AbstractModel.h @@ -12,31 +12,48 @@ namespace models { enum ModelType { Unknown, DTMC, CTMC, MDP, CTMDP }; -/* -// TODO: If we want this to work, it has to be in a cpp... :-) -std::ostream& operator<<(std::ostream& os, const ModelType type) -{ - switch (type) { - case Unknown: os << "Unknown"; break; - case DTMC: os << "DTMC"; break; - case CTMC: os << "CTMC"; break; - case MDP: os << "MDP"; break; - case CTMDP: os << "CTMDP"; break; - default: os << "Invalid ModelType"; break; - } - return os; -} -*/ +/*! + * @brief Stream output operator for ModelType. + */ +std::ostream& operator<<(std::ostream& os, ModelType const type); + +/*! + * @brief Base class for all model classes. + * + * This is base class defines a common interface for all models to identify + * their type and obtain the special model. + */ class AbstractModel { public: + /*! + * @brief Casts the model to the model type that was actually + * created. + * + * As all methods that work on generic models will use this + * AbstractModel class, this method provides a convenient way to + * cast an AbstractModel object to an object of a concrete model + * type, which can be obtained via getType(). The mapping from an + * element of the ModelType enum to the actual class must be done + * by the caller. + * + * This methods uses std::dynamic_pointer_cast internally. + * + * @return Shared pointer of new type to this object. + */ template std::shared_ptr as() { - //return *dynamic_cast(this); return std::dynamic_pointer_cast(std::shared_ptr(this)); } + /*! + * @brief Return the actual type of the model. + * + * Each model must implement this method. + * + * @return Type of the model. + */ virtual ModelType getType() = 0; };