Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor|Cleanup|libdoomsday: Added base class for definition records
Various types of definitions have a number of common methods, such as order(), so having a base class for the accessors is appropriate.
- Loading branch information
Showing
5 changed files
with
159 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** @file defs/definition.h | ||
* | ||
* @authors Copyright (c) 2014 Jaakko Keränen <jaakko.keranen@iki.fi> | ||
* | ||
* @par License | ||
* GPL: http://www.gnu.org/licenses/gpl.html | ||
* | ||
* <small>This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by the | ||
* Free Software Foundation; either version 2 of the License, or (at your | ||
* option) any later version. This program is distributed in the hope that it | ||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty | ||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
* Public License for more details. You should have received a copy of the GNU | ||
* General Public License along with this program; if not, see: | ||
* http://www.gnu.org/licenses</small> | ||
*/ | ||
|
||
#ifndef LIBDOOMSDAY_DEFN_DEFINITION_H | ||
#define LIBDOOMSDAY_DEFN_DEFINITION_H | ||
|
||
#include "../libdoomsday.h" | ||
#include <de/RecordAccessor> | ||
|
||
namespace defn { | ||
|
||
/** | ||
* Base class for definition records. | ||
*/ | ||
class LIBDOOMSDAY_PUBLIC Definition : public de::RecordAccessor | ||
{ | ||
public: | ||
Definition() : RecordAccessor(0) {} | ||
Definition(Definition const &other) : RecordAccessor(other) {} | ||
Definition(de::Record &d) : RecordAccessor(d) {} | ||
Definition(de::Record const &d) : RecordAccessor(d) {} | ||
|
||
de::Record &def(); | ||
de::Record const &def() const; | ||
|
||
/** | ||
* Determines if the definition point to a record. | ||
*/ | ||
operator bool() const; | ||
|
||
/** | ||
* Returns the ordinal of the definition. Ordinals are automatically set by | ||
* DEDRegister as definitions are created. | ||
*/ | ||
int order() const; | ||
|
||
/** | ||
* Inserts the default members into the definition. All definitions are required to | ||
* implement this, as it is automatically called for all newly created definitions. | ||
*/ | ||
virtual void resetToDefaults() = 0; | ||
}; | ||
|
||
} // namespace defn | ||
|
||
#endif // LIBDOOMSDAY_DEFN_DEFINITION_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** @file defs/definition.cpp | ||
* | ||
* @authors Copyright (c) 2014 Jaakko Keränen <jaakko.keranen@iki.fi> | ||
* | ||
* @par License | ||
* GPL: http://www.gnu.org/licenses/gpl.html | ||
* | ||
* <small>This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by the | ||
* Free Software Foundation; either version 2 of the License, or (at your | ||
* option) any later version. This program is distributed in the hope that it | ||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty | ||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
* Public License for more details. You should have received a copy of the GNU | ||
* General Public License along with this program; if not, see: | ||
* http://www.gnu.org/licenses</small> | ||
*/ | ||
|
||
#include "doomsday/defs/definition.h" | ||
|
||
using namespace de; | ||
|
||
namespace defn { | ||
|
||
Record &Definition::def() | ||
{ | ||
return const_cast<Record &>(accessedRecord()); | ||
} | ||
|
||
Record const &Definition::def() const | ||
{ | ||
return accessedRecord(); | ||
} | ||
|
||
int Definition::order() const | ||
{ | ||
if(!accessedRecordPtr()) return -1; | ||
return geti("__order__"); | ||
} | ||
|
||
Definition::operator bool() const | ||
{ | ||
return accessedRecordPtr() != 0; | ||
} | ||
|
||
} // namespace defn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters