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);
/// A filter for a specific file format
class FileFormat {
public:
virtual ~FileFormat() {}
/// File extension used by this file format
virtual String extension() = 0;
/// Name of the filter
......
......@@ -13,6 +13,7 @@
#include <util/reflect.hpp>
#include <util/action_stack.hpp>
#include <util/io/package.hpp>
#include <data/field.hpp> // for Set::value
#include <boost/scoped_ptr.hpp>
DECLARE_POINTER_TYPE(Card);
......
......@@ -15,6 +15,7 @@
#include <queue>
DECLARE_POINTER_TYPE(ThumbnailRequest);
class ThumbnailThreadWorker;
// ----------------------------------------------------------------------------- : ThumbnailRequest
......@@ -24,6 +25,8 @@ class ThumbnailRequest {
ThumbnailRequest(void* owner, const String& cache_name, const wxDateTime& modified)
: owner(owner), cache_name(cache_name), modified(modified) {}
virtual ~ThumbnailRequest() {}
/// Generate the thumbnail, called in another thread
virtual Image generate() = 0;
/// Store the thumbnail, called from the main thread
......
......@@ -141,7 +141,7 @@ void Reader::handle(Scriptable<T>& s) {
if (starts_with(s.script.unparsed, _("script:"))) {
s.script.unparsed = s.script.unparsed.substr(7);
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);
} else {
handle(s.value);
......
......@@ -15,17 +15,6 @@
class Context;
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
DECLARE_INTRUSIVE_POINTER_TYPE(ScriptValue);
......@@ -46,7 +35,7 @@ enum ScriptType
/// A value that can be handled by the scripting engine.
/// Actual values are derived types
class ScriptValue {
class ScriptValue : public IntrusivePtrBase {
public:
inline ScriptValue()
#ifdef USE_INTRUSIVE_PTR
......@@ -87,34 +76,8 @@ class ScriptValue {
virtual ScriptValueP next();
/// Return the number of items in this value (assuming it is a collection)
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_true; ///< The preallocated true value
extern ScriptValueP script_false; ///< The preallocated false value
......@@ -181,7 +144,7 @@ class ScriptCollection : public ScriptValue {
template <typename V>
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()) {
return toScript(it->second);
} else {
......@@ -191,7 +154,7 @@ ScriptValueP get_member(const map<String,V>& m, const String& name) {
template <typename K, typename V>
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()) {
return toScript(*it);
} else {
......
......@@ -48,6 +48,7 @@ class Action {
/// Base class/interface for objects that listen to actions
class ActionListener {
public:
virtual ~ActionListener() {}
/// Notification that an action a has been performed or undone
virtual void onAction(const Action& a, bool undone) = 0;
};
......
......@@ -11,17 +11,7 @@
#include <util/prec.hpp>
#include <util/dynamic_arg.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
#include <util/atomic.hpp>
// ----------------------------------------------------------------------------- : Age
......@@ -33,24 +23,24 @@ class Age {
Age() {
update();
}
Age(LONG age) : age(age) {}
Age(AtomicIntEquiv age) : age(age) {}
/// Update the age to become the newest one
inline void update() {
age = InterlockedIncrement(&new_age);
age = ++new_age;
}
/// Compare two ages, smaller means earlier
inline bool operator < (Age a) const { return age < a.age; }
/// A number corresponding to the age
inline LONG get() const { return age; }
inline AtomicIntEquiv get() const { return age; }
private:
/// This age
LONG age;
AtomicIntEquiv age;
/// Global age counter, value of the last age created
static volatile LONG new_age;
static AtomicInt new_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 generate the image
*/
DECLARE_DYNAMIC_ARG (long, last_update_age);
DECLARE_DYNAMIC_ARG (AtomicIntEquiv, last_update_age);
// ----------------------------------------------------------------------------- : EOF
#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 {
class InternalError : public Error {
public:
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 {
class FileNotFoundError : public PackageError {
public:
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 {
class FileParseError : public ParseError {
public:
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 @@
#ifdef __GNUC__
// GCC has a buildin typeof function, so it doesn't need (as much) hacks
#define DECLARE_TYPEOF(T)
#define DECLARE_TYPEOF_NO_REV(T)
#define DECLARE_TYPEOF_CONST(T)
#define DECLARE_TYPEOF_COLLECTION(T)
#define TYPEOF(Value) __typeof(Value)
......
......@@ -46,7 +46,7 @@ class IndexMap : private vector<Value> {
void init(const vector<Key>& keys) {
if (this->size() == keys.size()) return;
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;
assert(key);
if (key->index >= this->size()) this->resize(key->index + 1);
......@@ -82,8 +82,8 @@ class IndexMap : private vector<Value> {
/// 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) {
typename vector<Value>::const_iterator find(const Name& key) const {
for(typename vector<Value>::const_iterator it = begin() ; it != end() ; ++it) {
if (get_key_name(*it) == key) return it;
}
return end();
......
......@@ -11,6 +11,7 @@
#include <util/reflect.hpp>
#include <util/dynamic_arg.hpp>
#include <util/error.hpp>
class Package;
class wxFileInputStream;
......
......@@ -25,6 +25,7 @@
// Wx headers
#include <wx/setup.h>
#include <wx/wxprec.h>
#include <wx/wx.h>
#include <wx/image.h>
#include <wx/datetime.h>
......
......@@ -14,9 +14,11 @@
// ----------------------------------------------------------------------------- : Includes
// MOVEME
/// Using intrusive_ptr where possible? (as opposed to smart_ptr)
#define USE_INTRUSIVE_PTR
#include <util/atomic.hpp>
#ifdef HAVE_FAST_ATOMIC
/// Using intrusive_ptr where possible? (as opposed to smart_ptr)
#define USE_INTRUSIVE_PTR
#endif
#include <boost/shared_ptr.hpp>
#ifdef USE_INTRUSIVE_PTR
......@@ -100,6 +102,30 @@ inline shared_ptr<T> new_shared7(const A0& a0, const A1& a1, const A2& a2, const
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
#define DECLARE_INTRUSIVE_POINTER_TYPE DECLARE_POINTER_TYPE
#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
#define new_intrusive1 new_shared1
#define new_intrusive2 new_shared2
#define new_intrusive3 new_shared3
class IntrusivePtrBase {
public:
virtual ~IntrusivePtrBase();
protected:
/// Delete this object
virtual void destroy() {
delete this;
}
};
#endif
// ----------------------------------------------------------------------------- : EOF
......
......@@ -18,7 +18,7 @@
/** Intentionally uses slightly less then 0.5, to give a more consistent result
* when for instance something like "x/2" is used. */
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
......
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