Browse Source

added documentation for AbstractModel and operator<< for ModelType

main
gereon 12 years ago
parent
commit
650a0f0a27
  1. 26
      src/models/AbstractModel.cpp
  2. 49
      src/models/AbstractModel.h

26
src/models/AbstractModel.cpp

@ -0,0 +1,26 @@
#include "src/models/AbstractModel.h"
#include <iostream>
/*!
* 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;
}

49
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 <typename Model>
std::shared_ptr<Model> as() {
//return *dynamic_cast<Model*>(this);
return std::dynamic_pointer_cast<Model>(std::shared_ptr<AbstractModel>(this));
}
/*!
* @brief Return the actual type of the model.
*
* Each model must implement this method.
*
* @return Type of the model.
*/
virtual ModelType getType() = 0;
};

Loading…
Cancel
Save