default smart pointer type switched to intrusive_ptr

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@337 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2007-05-11 21:34:53 +00:00
parent 3b6743b110
commit 33fd2b5e18
103 changed files with 368 additions and 256 deletions
+8 -2
View File
@@ -13,7 +13,7 @@
#include <script/value.hpp>
class Script;
DECLARE_INTRUSIVE_POINTER_TYPE(Script);
DECLARE_POINTER_TYPE(Script);
template <typename T> class Defaultable;
template <typename T> class Scriptable;
@@ -39,6 +39,9 @@ class GetDefaultMember {
/// Handle an object: we don't match things with a name
template <typename T>
void handle(const Char* name, const T& object) {}
/// Don't handle a value
template <typename T>
inline void handleNoScript(const Char* name, T& value) {}
/// Handle an object: investigate children, or store it if we know how
void handle(const Char *);
@@ -50,7 +53,7 @@ class GetDefaultMember {
template <typename T> void handle(const vector<T>& c) { value = to_script(&c); }
template <typename K, typename V> void handle(const map<K,V>& c) { value = to_script(&c); }
template <typename K, typename V> void handle(const IndexMap<K,V>& c) { value = to_script(&c); }
template <typename T> void handle(const shared_ptr<T>& p) { value = to_script(p); }
template <typename T> void handle(const intrusive_ptr<T>& p) { value = to_script(p); }
void handle(const ScriptValueP&);
void handle(const ScriptP&);
private:
@@ -85,6 +88,9 @@ class GetMember : private GetDefaultMember {
gdm.handle(object);
}
}
/// Don't handle a value
template <typename T>
inline void handleNoScript(const Char* name, T& value) {}
/// Handle an object: investigate children
template <typename T> void handle(const T&);
/// Handle an index map: invistigate keys
+2 -2
View File
@@ -412,9 +412,9 @@ IMPLEMENT_REFLECTION(Packaged) {
REFLECT(short_name);
REFLECT(full_name);
REFLECT_N("icon", icon_filename);
REFLECT(position_hint);
REFLECT_NO_SCRIPT(position_hint);
REFLECT(version);
REFLECT_N("depends ons", dependencies); // hack for singular_form
REFLECT_NO_SCRIPT_N("depends ons", dependencies); // hack for singular_form
}
Packaged::Packaged()
+2 -2
View File
@@ -45,7 +45,7 @@ DECLARE_DYNAMIC_ARG(Package*, clipboard_package);
*
* TODO: maybe support sub packages (a package inside another package)?
*/
class Package {
class Package : public IntrusivePtrVirtualBase {
public:
// --------------------------------------------------- : Managing the outside of the package
@@ -177,7 +177,7 @@ class Package {
// ----------------------------------------------------------------------------- : Packaged
/// Dependencies of a package
class PackageDependency {
class PackageDependency : public IntrusivePtrBase<PackageDependency> {
public:
String package; ///< Name of the package someone depends on
Version version; ///< Minimal required version of that package
+6 -6
View File
@@ -65,12 +65,12 @@ PackagedP PackageManager::openAny(const String& name, bool just_header) {
return p;
} else {
// load with the right type, based on extension
if (fn.GetExt() == _("mse-game")) p = new_shared<Game>();
else if (fn.GetExt() == _("mse-style")) p = new_shared<StyleSheet>();
else if (fn.GetExt() == _("mse-locale")) p = new_shared<Locale>();
else if (fn.GetExt() == _("mse-include")) p = new_shared<IncludePackage>();
else if (fn.GetExt() == _("mse-symbol-font")) p = new_shared<SymbolFont>();
else if (fn.GetExt() == _("mse-export-template")) p = new_shared<ExportTemplate>();
if (fn.GetExt() == _("mse-game")) p = new_intrusive<Game>();
else if (fn.GetExt() == _("mse-style")) p = new_intrusive<StyleSheet>();
else if (fn.GetExt() == _("mse-locale")) p = new_intrusive<Locale>();
else if (fn.GetExt() == _("mse-include")) p = new_intrusive<IncludePackage>();
else if (fn.GetExt() == _("mse-symbol-font")) p = new_intrusive<SymbolFont>();
else if (fn.GetExt() == _("mse-export-template")) p = new_intrusive<ExportTemplate>();
else {
throw PackageError(_("Unrecognized package type: '") + fn.GetExt() + _("'\nwhile trying to open: ") + name);
}
+3 -3
View File
@@ -33,19 +33,19 @@ class PackageManager {
/// Open a package with the specified name (including extension)
template <typename T>
shared_ptr<T> open(const String& name) {
intrusive_ptr<T> open(const String& name) {
wxFileName fn(data_directory + _("/") + name);
fn.Normalize();
String filename = fn.GetFullPath();
// Is this package already loaded?
PackagedP& p = loaded_packages[filename];
shared_ptr<T> typedP = dynamic_pointer_cast<T>(p);
intrusive_ptr<T> typedP = dynamic_pointer_cast<T>(p);
if (typedP) {
typedP->loadFully();
return typedP;
} else {
// not loaded, or loaded with wrong type (i.e. with just_header)
p = typedP = new_shared<T>();
p = typedP = new_intrusive<T>();
typedP->open(filename);
return typedP;
}
+9 -5
View File
@@ -82,14 +82,18 @@ class Reader {
exitBlock();
}
}
/// Handle a value
template <typename T>
inline void handleNoScript(const Char* name, T& value) { handle(name,value); }
/// Reads a vector from the input stream
template <typename T>
void handle(const Char* name, vector<T>& vector);
/// Reads an object of type T from the input stream
template <typename T> void handle(T& object);
/// Reads a shared_ptr from the input stream
template <typename T> void handle(shared_ptr<T>& pointer);
/// Reads a intrusive_ptr from the input stream
template <typename T> void handle(intrusive_ptr<T>& pointer);
/// Reads a map from the input stream
template <typename V> void handle(map<String,V>& m);
/// Reads an IndexMap from the input stream, reads only keys that already exist in the map
@@ -178,8 +182,8 @@ class Reader {
* This function can be overloaded to provide different behaviour
*/
template <typename T>
shared_ptr<T> read_new(Reader& reader) {
return new_shared<T>();
intrusive_ptr<T> read_new(Reader& reader) {
return new_intrusive<T>();
}
/// Update the 'index' member of a value for use by IndexMap
@@ -197,7 +201,7 @@ void Reader::handle(const Char* name, vector<T>& vector) {
}
template <typename T>
void Reader::handle(shared_ptr<T>& pointer) {
void Reader::handle(intrusive_ptr<T>& pointer) {
if (!pointer) pointer = read_new<T>(*this);
handle(*pointer);
}
+7 -3
View File
@@ -45,6 +45,10 @@ class Writer {
handle(object);
exitBlock();
}
/// Handle a value
template <typename T>
inline void handleNoScript(const Char* name, T& value) { handle(name,value); }
/// Write a vector to the output stream
template <typename T>
void handle(const Char* name, const vector<T>& vector);
@@ -55,8 +59,8 @@ class Writer {
/// Write an object of type T to the output stream
template <typename T> void handle(const T& object);
/// Write a shared_ptr to the output stream
template <typename T> void handle(const shared_ptr<T>& pointer);
/// Write a intrusive_ptr to the output stream
template <typename T> void handle(const intrusive_ptr<T>& pointer);
/// Write a map to the output stream
template <typename K, typename V> void handle(const map<K,V>& map);
/// Write an IndexMap to the output stream
@@ -107,7 +111,7 @@ void Writer::handle(const Char* name, const vector<T>& vec) {
}
template <typename T>
void Writer::handle(const shared_ptr<T>& pointer) {
void Writer::handle(const intrusive_ptr<T>& pointer) {
if (pointer) handle(*pointer);
}