Added version number to files; IndexMap now works with GetMember

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@40 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2006-10-19 21:01:17 +00:00
parent 440cec2f8c
commit c15bc94ee7
13 changed files with 115 additions and 25 deletions
+11 -1
View File
@@ -41,7 +41,8 @@ class IndexMap : private vector<Value> {
void init(const vector<Key>& keys) {
if (!this->empty()) return;
this->reserve(keys.size());
FOR_EACH_CONST(key, keys) {
for(vector<Key>::const_iterator it = keys.begin() ; it != keys.end() ; ++it) {
const Key& key = *it;
assert(key);
if (key->index >= this->size()) this->resize(key->index + 1);
init_object(key, (*this)[key->index]);
@@ -68,6 +69,15 @@ class IndexMap : private vector<Value> {
return key->index < this.size() && get_key((*this)[key->index]) == key
}
/// Find a value given the key name, return an iterator
template <typename Name>
const_iterator find(const Name& key) const {
for(vector<Value>::const_iterator it = begin() ; it != end() ; ++it) {
if (get_key_name(*it) == key) return it;
}
return end();
}
private:
using vector<Value>::operator [];
};
+2
View File
@@ -29,6 +29,8 @@ class GetDefaultMember {
inline bool reading() const { return false; }
inline bool isComplex() const { return false; }
inline void handleAppVersion() {} // no effect
/// The result, or script_nil if the member was not found
inline ScriptValueP result() { return value; }
+1
View File
@@ -386,6 +386,7 @@ void Packaged::open(const String& package) {
Package::open(package);
Reader reader(openIn(typeName()), absoluteFilename() + _("/") + typeName());
try {
reader.handleAppVersion();
reader.handle(*this);
} catch (const ParseError& err) {
throw FileParseError(err.what(), absoluteFilename() + _("/") + typeName()); // more detailed message
+15
View File
@@ -31,6 +31,21 @@ Reader::Reader(const String& filename)
}
void Reader::handleAppVersion() {
if (enterBlock(_("mse_version"))) {
handle(app_version);
if (::app_version < app_version) {
wxMessageBox(
filename + _("\n")
_("This file is made with a newer version of Magic Set Editor (")+ app_version.toString() +_(").\n")
_("When you open it, some aspects of the file may be lost.\n")
_("It is recommended that you upgrade to the latest version.\n")
_("Visit http:://magicseteditor.sourceforge.net/"), _("Warning"), wxOK | wxICON_EXCLAMATION);
}
exitBlock();
}
}
void Reader::warning(const String& msg) {
wxMessageBox((msg + _("\nOn line: ")) << line_number << _("\nIn file: ") << filename, _("Warning"), wxOK | wxICON_EXCLAMATION);
}
+12 -1
View File
@@ -10,10 +10,13 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <util/version.hpp>
#include <wx/txtstrm.h>
template <typename T> class Defaultable;
template <typename T> class Scriptable;
DECLARE_POINTER_TYPE(Game);
DECLARE_POINTER_TYPE(StyleSheet);
// ----------------------------------------------------------------------------- : Reader
@@ -44,6 +47,9 @@ class Reader {
/// Is the thing currently being read 'complex', i.e. does it have children
inline bool isComplex() const { return value.empty(); }
/// Read and check the application version
void handleAppVersion();
/// Show a warning message, but continue reading
void warning(const String& msg);
@@ -72,9 +78,14 @@ class Reader {
template <typename T> void handle(Defaultable<T>&);
/// Reads a Scriptable from the input stream
template <typename T> void handle(Scriptable<T>&);
// special behaviour
void handle(GameP&);
void handle(StyleSheet&);
private:
// --------------------------------------------------- : Data
/// App version this file was made with
Version app_version;
private:
/// The line we read
String line;
/// The key and value of the last line we read
+5
View File
@@ -9,6 +9,7 @@
#include "writer.hpp"
#include <util/vector2d.hpp>
#include <util/error.hpp>
#include <util/version.hpp>
// ----------------------------------------------------------------------------- : Writer
@@ -22,6 +23,10 @@ Writer::Writer(const OutputStreamP& output)
}
void Writer::handleAppVersion() {
handle(_("mse_version"), app_version);
}
void Writer::enterBlock(const Char* name) {
// indenting into a sub-block?
if (just_opened) {
+8
View File
@@ -14,6 +14,8 @@
template <typename T> class Defaultable;
template <typename T> class Scriptable;
DECLARE_POINTER_TYPE(Game);
DECLARE_POINTER_TYPE(StyleSheet);
// ----------------------------------------------------------------------------- : Writer
@@ -30,6 +32,9 @@ class Writer {
inline bool reading() const { return false; }
inline bool isComplex() const { return false; }
/// Write the application version
void handleAppVersion();
// --------------------------------------------------- : Handling objects
/// Handle an object: write it under the given name
template <typename T>
@@ -58,6 +63,9 @@ class Writer {
template <typename T> void handle(const Defaultable<T>&);
/// Write an object of type Scriptable<T> to the output stream
template <typename T> void handle(const Scriptable<T>&);
// special behaviour
void handle(const GameP&);
void handle(const StyleSheet&);
private:
// --------------------------------------------------- : Data
+9 -13
View File
@@ -25,13 +25,15 @@ struct Version {
Version() : version(0) {}
Version(UInt version) : version(version) {}
bool operator < (Version v) { return version < v.versionSuffix; }
inline bool operator < (Version v) const { return version < v.version; }
/// Convert a version number to a string
String toString();
String toString() const;
/// Get the version number as an integer number
UInt toNumber() const;
/// Convert a string to a version number
static Version fromString(UInt version);
static Version fromString(const String& version);
private:
UInt version; ///< Version number encoded as aabbcc, where a=major, b=minor, c=revision
@@ -39,20 +41,14 @@ struct Version {
// ----------------------------------------------------------------------------- : Versions
/// The verwsion number of MSE
const Version app_version = 000300; // 0.3.0
const Char* version_suffix = _(" (beta)");
/// The version number of MSE
extern const Version app_version;
extern const Char* version_suffix;
/// File version, usually the same as program version,
/** When no files are changed the file version is not incremented
* Changes:
* 0.2.0 : start of version numbering practice
* 0.2.2 : _("include file")
* 0.2.6 : fix in settings loading
* 0.2.7 : new tag system, different style of close tags
* 0.3.0 : port of code to C++
*/
const Version file_version = 000300; // 0.3.0
extern const Version file_version;
// ----------------------------------------------------------------------------- : EOF
#endif