diff options
Diffstat (limited to 'project2/variables-moduri.cpp')
-rw-r--r-- | project2/variables-moduri.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/project2/variables-moduri.cpp b/project2/variables-moduri.cpp new file mode 100644 index 0000000..f6793e1 --- /dev/null +++ b/project2/variables-moduri.cpp @@ -0,0 +1,34 @@ +#include "variables.h" +#include "xmlObjectLoader.h" +#include "xmlStorage.h" +#include "appEngine.h" + +/// Variable implementation to access URI path fragments +class VariableUri : public VariableImplDyn { + public: + VariableUri(const xmlpp::Element * e) : + VariableImplDyn(e), + index(atoi(e->get_attribute_value("index").c_str())) + { + } + const VariableType & value() const + { + if (!cacheValid) { + try { + cache = ApplicationEngine::getCurrent()->env()->getParamUri(index); + } + catch (UriElementOutOfRange) { + if (!defaultValue) { + throw; + } + cache = (*defaultValue)(); + } + cacheValid = true; + } + return cache; + } + private: + unsigned int index; +}; +DECLARE_COMPONENT_LOADER("uri", VariableUri, VariableLoader); + |