summaryrefslogtreecommitdiff
path: root/project2/variables.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'project2/variables.cpp')
-rw-r--r--project2/variables.cpp77
1 files changed, 66 insertions, 11 deletions
diff --git a/project2/variables.cpp b/project2/variables.cpp
index 9aa1a5b..07d30aa 100644
--- a/project2/variables.cpp
+++ b/project2/variables.cpp
@@ -30,7 +30,15 @@ class VariableSession : public VariableImplDyn {
VariableSession(const Glib::ustring & src) : VariableImplDyn(src) { }
const Glib::ustring & value() const
{
- cache = ApplicationEngine::getCurrent()->session()->GetValue(source.substr(1));
+ try {
+ cache = ApplicationEngine::getCurrent()->session()->GetValue(name);
+ }
+ catch (Session::VariableNotFound) {
+ if (!defaultValue) {
+ throw;
+ }
+ cache = *defaultValue;
+ }
return cache;
}
};
@@ -41,7 +49,15 @@ class VariableParam : public VariableImplDyn {
const Glib::ustring & value() const
{
if (!cacheValid) {
- cache = ApplicationEngine::getCurrent()->env()->getParamQuery(source.substr(1));
+ try {
+ cache = ApplicationEngine::getCurrent()->env()->getParamQuery(name);
+ }
+ catch (ApplicationEngine::ParamNotFound) {
+ if (!defaultValue) {
+ throw;
+ }
+ cache = *defaultValue;
+ }
cacheValid = true;
}
return cache;
@@ -54,7 +70,15 @@ class VariableUri : public VariableImplDyn {
const Glib::ustring & value() const
{
if (!cacheValid) {
- cache = ApplicationEngine::getCurrent()->env()->getParamUri(source.substr(1));
+ try {
+ cache = ApplicationEngine::getCurrent()->env()->getParamUri(atoi(name.c_str()));
+ }
+ catch (ApplicationEngine::UriElementOutOfRange) {
+ if (!defaultValue) {
+ throw;
+ }
+ cache = *defaultValue;
+ }
cacheValid = true;
}
return cache;
@@ -73,16 +97,33 @@ class VariableParent : public VariableImplDyn, public RowUser {
const Glib::ustring & value() const
{
if (!cacheValid) {
- if (!row) {
- PerRowValues::RowValuesStack::const_reverse_iterator r = PerRowValues::Stack().rbegin();
- for (size_t p = depth; --p; r++) ;
- row = *r;
- row->use(this);
- if (dep) {
- row->use(dep);
+ try {
+ if (!row) {
+ PerRowValues::RowValuesStack::const_reverse_iterator r = PerRowValues::Stack().rbegin();
+ for (size_t p = depth; --p; r++) ;
+ if (r == PerRowValues::Stack().rend()) {
+ throw PerRowValues::ParentOutOfRange();
+ }
+ row = *r;
+ row->use(this);
+ if (dep) {
+ row->use(dep);
+ }
}
+ cache = row->getCurrentValue(source);
+ }
+ catch (PerRowValues::ParentOutOfRange) {
+ if (!defaultValue) {
+ throw;
+ }
+ cache = *defaultValue;
+ }
+ catch (PerRowValues::FieldDoesNotExist) {
+ if (!defaultValue) {
+ throw;
+ }
+ cache = *defaultValue;
}
- cache = row->getCurrentValue(source);
cacheValid = true;
}
return cache;
@@ -170,3 +211,17 @@ Variable::create(const Glib::ustring & s, RowUser * dep)
}
}
+VariableImpl::VariableImpl(const Glib::ustring & src) :
+ source(src)
+{
+ Glib::ustring::const_iterator nameStart = std::find_if(source.begin(), source.end(), Glib::Unicode::isalnum);
+ Glib::ustring::const_iterator nameEnd = std::find(nameStart, source.end(), '|');
+ name = Glib::ustring(nameStart, nameEnd);
+ Glib::ustring::const_iterator defaultStart = nameEnd;
+ if (defaultStart != source.end()) {
+ defaultStart++;
+ Glib::ustring::const_iterator defaultEnd = source.end();
+ defaultValue = Glib::ustring(defaultStart, defaultEnd);
+ }
+}
+