Skip to content

Commit

Permalink
Refactor|libcore|Script: Apply PIMPL in the Script class
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Nov 8, 2014
1 parent 2490658 commit 0310fec
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 21 deletions.
16 changes: 4 additions & 12 deletions doomsday/libcore/include/de/scriptsys/script.h
Expand Up @@ -65,8 +65,6 @@ class DENG2_PUBLIC Script
*/
Script(File const &file);

virtual ~Script();

/**
* Parses a source into statements, replacing any statements currently
* in the Script. The user must ensure that the script is not currently
Expand All @@ -82,26 +80,20 @@ class DENG2_PUBLIC Script
*
* @param path Path.
*/
void setPath(String const &path) { _path = path; }
void setPath(String const &path);

String const &path() const { return _path; }
String const &path() const;

/// Returns the statement that begins the script. This is where
/// a process begins the execution of a script.
Statement const *firstStatement() const;

/// Returns a modifiable reference to the main statement compound
/// of the script.
Compound &compound() {
return _compound;
}
Compound &compound();

private:
Compound _compound;

/// File path where the script was loaded. Will be visible in the namespace
/// of the process executing the script.
String _path;
DENG2_PRIVATE(d)
};

} // namespace de
Expand Down
43 changes: 34 additions & 9 deletions doomsday/libcore/src/scriptsys/script.cpp
Expand Up @@ -21,31 +21,56 @@
#include "de/Parser"
#include "de/File"

using namespace de;
namespace de {

Script::Script()
DENG2_PIMPL_NOREF(Script)
{
Compound compound;

/// File path where the script was loaded. Will be visible in the namespace
/// of the process executing the script.
String path;
};

Script::Script() : d(new Instance)
{}

Script::Script(String const &source)
Script::Script(String const &source) : d(new Instance)
{
Parser().parse(source, *this);
}

Script::Script(File const &file) : _path(file.path())
Script::Script(File const &file) : d(new Instance)
{
d->path = file.path();
Parser().parse(String::fromUtf8(Block(file)), *this);
}

Script::~Script()
{}

void Script::parse(String const &source)
{
_compound.clear();
d->compound.clear();
Parser().parse(source, *this);
}

void Script::setPath(String const &path)
{
d->path = path;
}

String const &Script::path() const
{
return d->path;
}

Statement const *Script::firstStatement() const
{
return _compound.firstStatement();
return d->compound.firstStatement();
}

Compound &Script::compound()
{
return d->compound;
}

} // namespace de

0 comments on commit 0310fec

Please sign in to comment.