mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Some more data types; dynamic arguments
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@5 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
//+----------------------------------------------------------------------------+
|
||||
//| 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_DYNAMIC_ARG
|
||||
#define HEADER_UTIL_DYNAMIC_ARG
|
||||
|
||||
/** @file util/dynamic_arg.hpp
|
||||
*
|
||||
* @brief Support for 'dynamicly scopped' arguments.
|
||||
* This header
|
||||
*/
|
||||
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#include <util/prec.hpp>
|
||||
|
||||
// ----------------------------------------------------------------------------- : Dynamic argument
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# define THREAD_LOCAL __declspec(thread)
|
||||
#else
|
||||
# define THREAD_LOCAL __thread
|
||||
#endif
|
||||
|
||||
/// Declare a dynamic argument.
|
||||
/** The value of the argument can be got with: name()
|
||||
* To change the value use WITH_DYNAMIC_ARG(name, newValue) { ... }
|
||||
* To be used in a header file. Use IMPLEMENT_DYN_ARG in a source file
|
||||
*/
|
||||
#define DECLARE_DYNAMIC_ARG(Type, name) \
|
||||
extern THREAD_LOCAL Type name##_private; \
|
||||
inline Type name() { return name##_private; } \
|
||||
class name##_changer { \
|
||||
public: \
|
||||
inline name##_changer(Type const& newValue) \
|
||||
: oldValue(name##_private) { \
|
||||
name##_private = newValue; \
|
||||
} \
|
||||
inline ~name##_changer() { \
|
||||
name##_private = oldValue; \
|
||||
} \
|
||||
inline operator bool() { return true; } \
|
||||
private: \
|
||||
Type oldValue; \
|
||||
}
|
||||
|
||||
/// Implementation of a dynamic argument
|
||||
#define IMPLEMENT_DYNAMIC_ARG(Type, name, initial) \
|
||||
THREAD_LOCAL Type name##_private = initial;
|
||||
|
||||
/// Locally change the value of a dynamic argument
|
||||
/** Usage:
|
||||
* @code
|
||||
* // here name() == old value
|
||||
* WITH_DYNAMIC_ARG(name, newValue) {
|
||||
* // here name() == newValue
|
||||
* }
|
||||
* // here name() == old value
|
||||
* @endcode
|
||||
*/
|
||||
#define WITH_DYNAMIC_ARG(name, value) \
|
||||
if (name##_changer(value))
|
||||
|
||||
// ----------------------------------------------------------------------------- : EOF
|
||||
#endif
|
||||
+26
-14
@@ -41,34 +41,39 @@
|
||||
#define TYPEOF_CIT(Value) TypeOf<typeid(Value)>::const_iterator
|
||||
/// The type of a reverse iterator
|
||||
#define TYPEOF_RIT(Value) TypeOf<typeid(Value)>::reverse_iterator
|
||||
/// The type of a value
|
||||
/// The type of a reference
|
||||
#define TYPEOF_REF(Value) TypeOf<typeid(Value)>::reference
|
||||
/// The type of a const reference
|
||||
#define TYPEOF_CREF(Value) TypeOf<typeid(Value)>::const_reference
|
||||
|
||||
/// Declare typeof magic for a specific type
|
||||
#define DECLARE_TYPEOF(T) \
|
||||
template<> struct TypeOf<typeid(T)> { \
|
||||
typedef T type; \
|
||||
typedef T::iterator iterator; \
|
||||
typedef T::const_iterator const_iterator; \
|
||||
typedef T type; \
|
||||
typedef T::iterator iterator; \
|
||||
typedef T::const_iterator const_iterator; \
|
||||
typedef T::reverse_iterator reverse_iterator; \
|
||||
typedef T::reference reference; \
|
||||
typedef T::reference reference; \
|
||||
typedef T::const_reference const_reference; \
|
||||
}
|
||||
/// Declare typeof magic for a specific type that doesn't support reverse iterators
|
||||
#define DECLARE_TYPEOF_NO_REV(T) \
|
||||
template<> struct TypeOf<typeid(T)> { \
|
||||
typedef T type; \
|
||||
typedef T::iterator iterator; \
|
||||
typedef T::const_iterator const_iterator; \
|
||||
typedef T::reference reference; \
|
||||
typedef T type; \
|
||||
typedef T::iterator iterator; \
|
||||
typedef T::const_iterator const_iterator; \
|
||||
typedef T::reference reference; \
|
||||
typedef T::const_reference const_reference; \
|
||||
}
|
||||
/// Declare typeof magic for a specific type, using const iterators
|
||||
#define DECLARE_TYPEOF_CONST(T) \
|
||||
template<> struct TypeOf<typeid(T)> { \
|
||||
typedef T type; \
|
||||
typedef T::const_iterator iterator; \
|
||||
typedef T::const_iterator const_iterator; \
|
||||
typedef T::const_reverse_iterator reverse_iterator; \
|
||||
typedef T::const_reference reference; \
|
||||
typedef T type; \
|
||||
typedef T::const_iterator iterator; \
|
||||
typedef T::const_iterator const_iterator; \
|
||||
typedef T::reverse_iterator reverse_iterator; \
|
||||
typedef T::const_reference reference; \
|
||||
typedef T::const_reference const_reference; \
|
||||
}
|
||||
|
||||
|
||||
@@ -134,6 +139,13 @@
|
||||
#define FOR_EACH(Elem,Collection) \
|
||||
FOR_EACH_T(TYPEOF_IT(Collection), TYPEOF_REF(Collection), Elem, Collection)
|
||||
|
||||
/// Iterate over a collection whos type must be declared with DECLARE_TYPEOF
|
||||
/** Uses a const iterator
|
||||
* Usage: FOR_EACH_CONST(e,collect) { body-of-loop }
|
||||
*/
|
||||
#define FOR_EACH_CONST(Elem,Collection) \
|
||||
FOR_EACH_T(TYPEOF_CIT(Collection), TYPEOF_CREF(Collection), Elem, Collection)
|
||||
|
||||
/// Iterate over a collection whos type must be declared with DECLARE_TYPEOF
|
||||
/** Iterates using a reverse_iterator
|
||||
* Usage: FOR_EACH_REVERSE(e,collect) { body-of-loop }
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
/// A kind of map of K->V, with the following properties:
|
||||
/** - K must have a unique member ->index of type UInt
|
||||
* - There must exist a function initObject(K, V&)
|
||||
* that stores a new V object for a given key in v
|
||||
* that stores a new V object for a given key in the reference
|
||||
* - O(1) inserts and lookups
|
||||
*/
|
||||
template <typename Key, typename Value>
|
||||
@@ -35,10 +35,10 @@ class IndexMap : private vector<Value> {
|
||||
void init(const vector<Key>& keys) {
|
||||
if (!this->empty()) return;
|
||||
this->reserve(keys.size());
|
||||
FOR_EACH(it, keys) {
|
||||
Key& k = *it;
|
||||
if (k->index >= this->size()) this->resize(k->index + 1);
|
||||
initObject(k, (*this)[k->index]);
|
||||
FOR_EACH_CONST(key, keys) {
|
||||
assert(key);
|
||||
if (key->index >= this->size()) this->resize(key->index + 1);
|
||||
initObject(key, (*this)[key->index]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@
|
||||
|
||||
/** @file util/prec.hpp
|
||||
*
|
||||
* Precompiled header, and aliasses for common types
|
||||
* @brief Precompiled header, and aliasses for common types
|
||||
*/
|
||||
|
||||
// ----------------------------------------------------------------------------- : Compiler specific
|
||||
|
||||
@@ -20,7 +20,8 @@
|
||||
// ----------------------------------------------------------------------------- : Declaring reflection
|
||||
|
||||
/// Declare that a class supports reflection
|
||||
/// Reflection allows the member variables of a class to be inspected at runtime.
|
||||
/** Reflection allows the member variables of a class to be inspected at runtime.
|
||||
*/
|
||||
#define DECLARE_REFLECTION() \
|
||||
protected: \
|
||||
template<class Tag> void reflect_impl(Tag& tag); \
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#include <util/for_each.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
using namespace boost;
|
||||
|
||||
@@ -22,7 +23,8 @@ using namespace boost;
|
||||
/// Declares the type TypeP as a shared_ptr<Type>
|
||||
#define DECLARE_POINTER_TYPE(Type) \
|
||||
class Type; \
|
||||
typedef shared_ptr<Type> Type##P
|
||||
typedef shared_ptr<Type> Type##P; \
|
||||
DECLARE_TYPEOF_COLLECTION(Type##P)
|
||||
|
||||
// ----------------------------------------------------------------------------- : Creating
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#include "prec.hpp"
|
||||
#include "for_each.hpp"
|
||||
#include <ctype.h>
|
||||
#include <boost/preprocessor/cat.hpp>
|
||||
|
||||
@@ -7,6 +7,11 @@
|
||||
#ifndef HEADER_UTIL_WINDOW_ID
|
||||
#define HEADER_UTIL_WINDOW_ID
|
||||
|
||||
/** @file util/window_id.hpp
|
||||
*
|
||||
* @brief Enumerations of all window ids used.
|
||||
*/
|
||||
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
// ----------------------------------------------------------------------------- : Menu ids
|
||||
|
||||
Reference in New Issue
Block a user