Commit c155ce75 authored by twanvl's avatar twanvl

Fixed compilation errors for gcc@linux (not all yet).

parent 1cfe91f5
...@@ -22,6 +22,7 @@ DECLARE_POINTER_TYPE(FileFormat); ...@@ -22,6 +22,7 @@ DECLARE_POINTER_TYPE(FileFormat);
/// A filter for a specific file format /// A filter for a specific file format
class FileFormat { class FileFormat {
public: public:
virtual ~FileFormat() {}
/// File extension used by this file format /// File extension used by this file format
virtual String extension() = 0; virtual String extension() = 0;
/// Name of the filter /// Name of the filter
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <util/reflect.hpp> #include <util/reflect.hpp>
#include <util/action_stack.hpp> #include <util/action_stack.hpp>
#include <util/io/package.hpp> #include <util/io/package.hpp>
#include <data/field.hpp> // for Set::value
#include <boost/scoped_ptr.hpp> #include <boost/scoped_ptr.hpp>
DECLARE_POINTER_TYPE(Card); DECLARE_POINTER_TYPE(Card);
...@@ -131,7 +132,7 @@ class SetView : public ActionListener { ...@@ -131,7 +132,7 @@ class SetView : public ActionListener {
public: public:
SetView(); SetView();
~SetView(); ~SetView();
/// Get the set that is currently being viewed /// Get the set that is currently being viewed
inline SetP getSet() { return set; } inline SetP getSet() { return set; }
/// Change the set that is being viewed /// Change the set that is being viewed
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <queue> #include <queue>
DECLARE_POINTER_TYPE(ThumbnailRequest); DECLARE_POINTER_TYPE(ThumbnailRequest);
class ThumbnailThreadWorker;
// ----------------------------------------------------------------------------- : ThumbnailRequest // ----------------------------------------------------------------------------- : ThumbnailRequest
...@@ -24,6 +25,8 @@ class ThumbnailRequest { ...@@ -24,6 +25,8 @@ class ThumbnailRequest {
ThumbnailRequest(void* owner, const String& cache_name, const wxDateTime& modified) ThumbnailRequest(void* owner, const String& cache_name, const wxDateTime& modified)
: owner(owner), cache_name(cache_name), modified(modified) {} : owner(owner), cache_name(cache_name), modified(modified) {}
virtual ~ThumbnailRequest() {}
/// Generate the thumbnail, called in another thread /// Generate the thumbnail, called in another thread
virtual Image generate() = 0; virtual Image generate() = 0;
/// Store the thumbnail, called from the main thread /// Store the thumbnail, called from the main thread
...@@ -66,7 +69,7 @@ class ThumbnailThread { ...@@ -66,7 +69,7 @@ class ThumbnailThread {
deque<ThumbnailRequestP> open_requests; ///< Requests on which work hasn't finished deque<ThumbnailRequestP> open_requests; ///< Requests on which work hasn't finished
vector<pair<ThumbnailRequestP,Image> > closed_requests; ///< Requests for which work is completed vector<pair<ThumbnailRequestP,Image> > closed_requests; ///< Requests for which work is completed
set<ThumbnailRequestP> request_names; ///< Requests that haven't been stored yet, to prevent duplicates set<ThumbnailRequestP> request_names; ///< Requests that haven't been stored yet, to prevent duplicates
friend class ThumbnailThreadWorker; friend class ThumbnailThreadWorker;
ThumbnailThreadWorker* worker; ///< The worker thread. invariant: no requests ==> worker==nullptr ThumbnailThreadWorker* worker; ///< The worker thread. invariant: no requests ==> worker==nullptr
}; };
......
...@@ -141,7 +141,7 @@ void Reader::handle(Scriptable<T>& s) { ...@@ -141,7 +141,7 @@ void Reader::handle(Scriptable<T>& s) {
if (starts_with(s.script.unparsed, _("script:"))) { if (starts_with(s.script.unparsed, _("script:"))) {
s.script.unparsed = s.script.unparsed.substr(7); s.script.unparsed = s.script.unparsed.substr(7);
s.script.parse(*this); s.script.parse(*this);
} else if (s.script.unparsed.find_first_of('{') != String.npos) { } else if (s.script.unparsed.find_first_of('{') != String::npos) {
s.script.parse(*this, true); s.script.parse(*this, true);
} else { } else {
handle(s.value); handle(s.value);
......
...@@ -15,17 +15,6 @@ ...@@ -15,17 +15,6 @@
class Context; class Context;
class Dependency; class Dependency;
#ifdef _MSC_VER
extern "C" {
LONG __cdecl _InterlockedIncrement(LONG volatile *Addend);
LONG __cdecl _InterlockedDecrement(LONG volatile *Addend);
}
#pragma intrinsic (_InterlockedIncrement)
#define InterlockedIncrement _InterlockedIncrement
#pragma intrinsic (_InterlockedDecrement)
#define InterlockedDecrement _InterlockedDecrement
#endif
// ----------------------------------------------------------------------------- : ScriptValue // ----------------------------------------------------------------------------- : ScriptValue
DECLARE_INTRUSIVE_POINTER_TYPE(ScriptValue); DECLARE_INTRUSIVE_POINTER_TYPE(ScriptValue);
...@@ -46,7 +35,7 @@ enum ScriptType ...@@ -46,7 +35,7 @@ enum ScriptType
/// A value that can be handled by the scripting engine. /// A value that can be handled by the scripting engine.
/// Actual values are derived types /// Actual values are derived types
class ScriptValue { class ScriptValue : public IntrusivePtrBase {
public: public:
inline ScriptValue() inline ScriptValue()
#ifdef USE_INTRUSIVE_PTR #ifdef USE_INTRUSIVE_PTR
...@@ -87,34 +76,8 @@ class ScriptValue { ...@@ -87,34 +76,8 @@ class ScriptValue {
virtual ScriptValueP next(); virtual ScriptValueP next();
/// Return the number of items in this value (assuming it is a collection) /// Return the number of items in this value (assuming it is a collection)
virtual int itemCount() const; virtual int itemCount() const;
protected:
/// Delete this object
virtual void destroy() {
delete this;
}
#ifdef USE_INTRUSIVE_PTR
private:
volatile LONG refCount;
friend void intrusive_ptr_add_ref(ScriptValue*);
friend void intrusive_ptr_release(ScriptValue*);
#endif
}; };
#ifdef USE_INTRUSIVE_PTR
inline void intrusive_ptr_add_ref(ScriptValue* p) {
//p->refCount += 1;
InterlockedIncrement(&p->refCount);
}
inline void intrusive_ptr_release(ScriptValue* p) {
if (InterlockedDecrement(&p->refCount) == 0) {
//if (--p->refCount == 0) {
p->destroy();
}
}
#endif
extern ScriptValueP script_nil; ///< The preallocated nil value extern ScriptValueP script_nil; ///< The preallocated nil value
extern ScriptValueP script_true; ///< The preallocated true value extern ScriptValueP script_true; ///< The preallocated true value
extern ScriptValueP script_false; ///< The preallocated false value extern ScriptValueP script_false; ///< The preallocated false value
...@@ -181,7 +144,7 @@ class ScriptCollection : public ScriptValue { ...@@ -181,7 +144,7 @@ class ScriptCollection : public ScriptValue {
template <typename V> template <typename V>
ScriptValueP get_member(const map<String,V>& m, const String& name) { ScriptValueP get_member(const map<String,V>& m, const String& name) {
map<String,V>::const_iterator it = m.find(name); typename map<String,V>::const_iterator it = m.find(name);
if (it != m.end()) { if (it != m.end()) {
return toScript(it->second); return toScript(it->second);
} else { } else {
...@@ -191,7 +154,7 @@ ScriptValueP get_member(const map<String,V>& m, const String& name) { ...@@ -191,7 +154,7 @@ ScriptValueP get_member(const map<String,V>& m, const String& name) {
template <typename K, typename V> template <typename K, typename V>
ScriptValueP get_member(const IndexMap<K,V>& m, const String& name) { ScriptValueP get_member(const IndexMap<K,V>& m, const String& name) {
IndexMap<K,V>::const_iterator it = m.find(name); typename IndexMap<K,V>::const_iterator it = m.find(name);
if (it != m.end()) { if (it != m.end()) {
return toScript(*it); return toScript(*it);
} else { } else {
......
...@@ -48,6 +48,7 @@ class Action { ...@@ -48,6 +48,7 @@ class Action {
/// Base class/interface for objects that listen to actions /// Base class/interface for objects that listen to actions
class ActionListener { class ActionListener {
public: public:
virtual ~ActionListener() {}
/// Notification that an action a has been performed or undone /// Notification that an action a has been performed or undone
virtual void onAction(const Action& a, bool undone) = 0; virtual void onAction(const Action& a, bool undone) = 0;
}; };
......
...@@ -11,17 +11,7 @@ ...@@ -11,17 +11,7 @@
#include <util/prec.hpp> #include <util/prec.hpp>
#include <util/dynamic_arg.hpp> #include <util/dynamic_arg.hpp>
#include <util/atomic.hpp>
#ifdef _MSC_VER
extern "C" {
LONG __cdecl _InterlockedIncrement(LONG volatile *Addend);
LONG __cdecl _InterlockedDecrement(LONG volatile *Addend);
}
#pragma intrinsic (_InterlockedIncrement)
#define InterlockedIncrement _InterlockedIncrement
#pragma intrinsic (_InterlockedDecrement)
#define InterlockedDecrement _InterlockedDecrement
#endif
// ----------------------------------------------------------------------------- : Age // ----------------------------------------------------------------------------- : Age
...@@ -33,24 +23,24 @@ class Age { ...@@ -33,24 +23,24 @@ class Age {
Age() { Age() {
update(); update();
} }
Age(LONG age) : age(age) {} Age(AtomicIntEquiv age) : age(age) {}
/// Update the age to become the newest one /// Update the age to become the newest one
inline void update() { inline void update() {
age = InterlockedIncrement(&new_age); age = ++new_age;
} }
/// Compare two ages, smaller means earlier /// Compare two ages, smaller means earlier
inline bool operator < (Age a) const { return age < a.age; } inline bool operator < (Age a) const { return age < a.age; }
/// A number corresponding to the age /// A number corresponding to the age
inline LONG get() const { return age; } inline AtomicIntEquiv get() const { return age; }
private: private:
/// This age /// This age
LONG age; AtomicIntEquiv age;
/// Global age counter, value of the last age created /// Global age counter, value of the last age created
static volatile LONG new_age; static AtomicInt new_age;
}; };
...@@ -60,7 +50,7 @@ class Age { ...@@ -60,7 +50,7 @@ class Age {
* if last_update_age > 0 they return whether the image is still up to date * if last_update_age > 0 they return whether the image is still up to date
* if last_update_age == 0 they generate the image * if last_update_age == 0 they generate the image
*/ */
DECLARE_DYNAMIC_ARG (long, last_update_age); DECLARE_DYNAMIC_ARG (AtomicIntEquiv, last_update_age);
// ----------------------------------------------------------------------------- : EOF // ----------------------------------------------------------------------------- : EOF
#endif #endif
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2006 Twan van Laarhoven |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
#ifndef HEADER_UTIL_ATOMIC
#define HEADER_UTIL_ATOMIC
/** @file util/atomic.hpp
*
* @brief Provides the type AtomicInt, which is an integer that can be incremented and decremented atomicly
*/
// ----------------------------------------------------------------------------- : Includes
// ----------------------------------------------------------------------------- : AtomicInt : windows
#ifdef _WX_MSW_
#ifdef _MSC_VER
extern "C" {
LONG __cdecl _InterlockedIncrement(LONG volatile *Addend);
LONG __cdecl _InterlockedDecrement(LONG volatile *Addend);
}
#pragma intrinsic (_InterlockedIncrement)
#define InterlockedIncrement _InterlockedIncrement
#pragma intrinsic (_InterlockedDecrement)
#define InterlockedDecrement _InterlockedDecrement
#endif
/// An integer which is equivalent to an AtomicInt, but which doesn't support attomic operations
typedef LONG AtomicIntEquiv;
/// An integer that can be incremented and decremented atomicly
class AtomicInt {
public:
AtomicInt(AtomicIntEquiv v) : v(v) {}
inline operator AtomicIntEquiv() const {
return v;
}
/// Attomicly increments this AtomicInt, returns the new value
inline AtomicIntEquiv operator ++ () {
return InterlockedIncrement(&v);
}
/// Attomicly decrements this AtomicInt, returns the new value
inline AtomicIntEquiv operator -- () {
return InterlockedDecrement(&v);
}
private:
AtomicIntEquiv v; ///< The value
};
/// We have a fast AtomicInt
#define HAVE_FAST_ATOMIC
// ----------------------------------------------------------------------------- : AtomicInt : portable
#else
/// An integer which is equivalent to an AtomicInt, but which doesn't support attomic operations
typedef long AtomicIntEquiv;
/// An integer that can be incremented and decremented atomicly
class AtomicInt {
public:
AtomicInt(AtomicIntEquiv v) : v(v) {}
inline operator AtomicIntEquiv() const {
return v;
}
/// Attomicly increments this AtomicInt, returns the new value
inline AtomicIntEquiv operator ++ () {
wxCriticalSectionLocker lock(cs);
return ++v;
}
/// Attomicly decrements this AtomicInt, returns the new value
inline AtomicIntEquiv operator -- () {
wxCriticalSectionLocker lock(cs);
return --v;
}
private:
AtomicIntEquiv v; ///< The value
wxCriticalSection cs; ///< Critical section protecting v
};
#endif
// ----------------------------------------------------------------------------- : EOF
#endif
...@@ -36,7 +36,7 @@ class Error { ...@@ -36,7 +36,7 @@ class Error {
class InternalError : public Error { class InternalError : public Error {
public: public:
inline InternalError(const String& str) inline InternalError(const String& str)
: Error(_ERROR_1_("internal error",str)) : Error(_ERROR_1_("internal error", str.c_str()))
{} {}
}; };
...@@ -52,7 +52,7 @@ class PackageError : public Error { ...@@ -52,7 +52,7 @@ class PackageError : public Error {
class FileNotFoundError : public PackageError { class FileNotFoundError : public PackageError {
public: public:
inline FileNotFoundError(const String& file, const String& package) inline FileNotFoundError(const String& file, const String& package)
: PackageError(_ERROR_2_("file not found",file,package)) : PackageError(_ERROR_2_("file not found", file.c_str(), package.c_str()))
{} {}
}; };
...@@ -68,7 +68,7 @@ class ParseError : public Error { ...@@ -68,7 +68,7 @@ class ParseError : public Error {
class FileParseError : public ParseError { class FileParseError : public ParseError {
public: public:
inline FileParseError(const String& err, const String& file) : inline FileParseError(const String& err, const String& file) :
ParseError(_ERROR_2_("file parse error",file,err)) ParseError(_ERROR_2_("file parse error", file.c_str(), err.c_str()))
{} {}
}; };
......
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
#ifdef __GNUC__ #ifdef __GNUC__
// GCC has a buildin typeof function, so it doesn't need (as much) hacks // GCC has a buildin typeof function, so it doesn't need (as much) hacks
#define DECLARE_TYPEOF(T) #define DECLARE_TYPEOF(T)
#define DECLARE_TYPEOF_NO_REV(T)
#define DECLARE_TYPEOF_CONST(T)
#define DECLARE_TYPEOF_COLLECTION(T) #define DECLARE_TYPEOF_COLLECTION(T)
#define TYPEOF(Value) __typeof(Value) #define TYPEOF(Value) __typeof(Value)
......
...@@ -46,7 +46,7 @@ class IndexMap : private vector<Value> { ...@@ -46,7 +46,7 @@ class IndexMap : private vector<Value> {
void init(const vector<Key>& keys) { void init(const vector<Key>& keys) {
if (this->size() == keys.size()) return; if (this->size() == keys.size()) return;
this->reserve(keys.size()); this->reserve(keys.size());
for(vector<Key>::const_iterator it = keys.begin() ; it != keys.end() ; ++it) { for(typename vector<Key>::const_iterator it = keys.begin() ; it != keys.end() ; ++it) {
const Key& key = *it; const Key& key = *it;
assert(key); assert(key);
if (key->index >= this->size()) this->resize(key->index + 1); if (key->index >= this->size()) this->resize(key->index + 1);
...@@ -82,8 +82,8 @@ class IndexMap : private vector<Value> { ...@@ -82,8 +82,8 @@ class IndexMap : private vector<Value> {
/// Find a value given the key name, return an iterator /// Find a value given the key name, return an iterator
template <typename Name> template <typename Name>
const_iterator find(const Name& key) const { typename vector<Value>::const_iterator find(const Name& key) const {
for(vector<Value>::const_iterator it = begin() ; it != end() ; ++it) { for(typename vector<Value>::const_iterator it = begin() ; it != end() ; ++it) {
if (get_key_name(*it) == key) return it; if (get_key_name(*it) == key) return it;
} }
return end(); return end();
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <util/reflect.hpp> #include <util/reflect.hpp>
#include <util/dynamic_arg.hpp> #include <util/dynamic_arg.hpp>
#include <util/error.hpp>
class Package; class Package;
class wxFileInputStream; class wxFileInputStream;
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
// Wx headers // Wx headers
#include <wx/setup.h> #include <wx/setup.h>
#include <wx/wxprec.h> #include <wx/wxprec.h>
#include <wx/wx.h>
#include <wx/image.h> #include <wx/image.h>
#include <wx/datetime.h> #include <wx/datetime.h>
......
...@@ -14,9 +14,11 @@ ...@@ -14,9 +14,11 @@
// ----------------------------------------------------------------------------- : Includes // ----------------------------------------------------------------------------- : Includes
// MOVEME #include <util/atomic.hpp>
/// Using intrusive_ptr where possible? (as opposed to smart_ptr) #ifdef HAVE_FAST_ATOMIC
#define USE_INTRUSIVE_PTR /// Using intrusive_ptr where possible? (as opposed to smart_ptr)
#define USE_INTRUSIVE_PTR
#endif
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#ifdef USE_INTRUSIVE_PTR #ifdef USE_INTRUSIVE_PTR
...@@ -99,7 +101,31 @@ inline shared_ptr<T> new_shared7(const A0& a0, const A1& a1, const A2& a2, const ...@@ -99,7 +101,31 @@ inline shared_ptr<T> new_shared7(const A0& a0, const A1& a1, const A2& a2, const
inline intrusive_ptr<T> new_intrusive2(const A0& a0, const A1& a1) { inline intrusive_ptr<T> new_intrusive2(const A0& a0, const A1& a1) {
return intrusive_ptr<T>(new T(a0, a1)); return intrusive_ptr<T>(new T(a0, a1));
} }
/// Base class for objects wishing to use intrusive_ptrs
class IntrusivePtrBase {
public:
virtual ~IntrusivePtrBase();
protected:
/// Delete this object
virtual void destroy() {
delete this;
}
private:
volatile AtomicInt ref_count;
friend void intrusive_ptr_add_ref(IntrusivePtrBase*);
friend void intrusive_ptr_release(IntrusivePtrBase*);
};
inline void intrusive_ptr_add_ref(IntrusivePtrBase* p) {
++p->ref_count;
}
inline void intrusive_ptr_release(IntrusivePtrBase* p) {
if (--p->ref_count == 0) {
p->destroy();
}
}
#else #else
#define DECLARE_INTRUSIVE_POINTER_TYPE DECLARE_POINTER_TYPE #define DECLARE_INTRUSIVE_POINTER_TYPE DECLARE_POINTER_TYPE
#define intrusive_ptr shared_ptr #define intrusive_ptr shared_ptr
...@@ -107,6 +133,17 @@ inline shared_ptr<T> new_shared7(const A0& a0, const A1& a1, const A2& a2, const ...@@ -107,6 +133,17 @@ inline shared_ptr<T> new_shared7(const A0& a0, const A1& a1, const A2& a2, const
#define new_intrusive1 new_shared1 #define new_intrusive1 new_shared1
#define new_intrusive2 new_shared2 #define new_intrusive2 new_shared2
#define new_intrusive3 new_shared3 #define new_intrusive3 new_shared3
class IntrusivePtrBase {
public:
virtual ~IntrusivePtrBase();
protected:
/// Delete this object
virtual void destroy() {
delete this;
}
};
#endif #endif
// ----------------------------------------------------------------------------- : EOF // ----------------------------------------------------------------------------- : EOF
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
/** Intentionally uses slightly less then 0.5, to give a more consistent result /** Intentionally uses slightly less then 0.5, to give a more consistent result
* when for instance something like "x/2" is used. */ * when for instance something like "x/2" is used. */
inline int to_int(double d) { inline int to_int(double d) {
return d > 0 ? d + 0.4999995 : d - 0.4999995; return static_cast<int>(d > 0 ? d + 0.4999995 : d - 0.4999995);
} }
// ----------------------------------------------------------------------------- : Vector2D // ----------------------------------------------------------------------------- : Vector2D
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment