Skip to content

Commit

Permalink
Cleanup|Config: Added get() method for array values
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Dec 9, 2012
1 parent d2e1e1a commit 2661ce5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions doomsday/engine/src/ui/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1551,7 +1551,7 @@ void Window_RestoreState(Window* wnd)
de::Config &config = de::App::config();

// The default state of the window is determined by these values.
de::ArrayValue &rect = config.getAs<de::ArrayValue>("window.main.rect");
de::ArrayValue &rect = config.geta("window.main.rect");
if(rect.size() >= 4)
{
QRect geom(rect.at(0).asNumber(), rect.at(1).asNumber(),
Expand All @@ -1562,7 +1562,7 @@ void Window_RestoreState(Window* wnd)
wnd->geometry.size.height = geom.height();
}

de::ArrayValue &normalRect = config.getAs<de::ArrayValue>("window.main.normalRect");
de::ArrayValue &normalRect = config.geta("window.main.normalRect");
if(normalRect.size() >= 4)
{
QRect geom(normalRect.at(0).asNumber(), normalRect.at(1).asNumber(),
Expand Down
6 changes: 6 additions & 0 deletions doomsday/libdeng2/include/de/core/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

namespace de
{
class ArrayValue;

/**
* Stores the configuration of everything. The application owns a Config.
* The default configuration is produced by executing the .de scripts
Expand Down Expand Up @@ -80,6 +82,10 @@ namespace de
/// Returns the value of @a name as a string.
String gets(String const &name);

/// Returns the value of @a name as an array value. An exception is thrown
/// if the variable does not have an array value.
ArrayValue &geta(String const &name);

template <typename ValueType>
ValueType &getAs(String const &name) {
ValueType *v = dynamic_cast<ValueType *>(&get(name));
Expand Down
6 changes: 6 additions & 0 deletions doomsday/libdeng2/src/core/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "de/Folder"
#include "de/ArrayValue"
#include "de/NumberValue"
#include "de/ArrayValue"
#include "de/Reader"
#include "de/Writer"
#include "de/Version"
Expand Down Expand Up @@ -178,4 +179,9 @@ String Config::gets(String const &name)
return get(name).asText();
}

ArrayValue &Config::geta(const String &name)
{
return getAs<ArrayValue>(name);
}

} // namespace de

0 comments on commit 2661ce5

Please sign in to comment.