mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
CMake file
Update to C++ 11: std::shared_ptr, for each loops Update to wxWidgets 3.0+
This commit is contained in:
@@ -359,7 +359,7 @@ void Context::closeScope(size_t scope) {
|
||||
|
||||
// ----------------------------------------------------------------------------- : Simple instructions : unary
|
||||
|
||||
void instrUnary (UnaryInstructionType i, ScriptValueP& a) {
|
||||
void instrUnary(UnaryInstructionType i, ScriptValueP& a) {
|
||||
switch (i) {
|
||||
case I_ITERATOR_C:
|
||||
a = a->makeIterator(a);
|
||||
|
||||
@@ -41,7 +41,7 @@ ScriptValueP unified(const ScriptValueP& a, const ScriptValueP& b);
|
||||
* So it has the dependency characteristics of both.
|
||||
*/
|
||||
class DependencyUnion : public ScriptValue {
|
||||
public:
|
||||
public:
|
||||
DependencyUnion(const ScriptValueP& a, const ScriptValueP& b)
|
||||
: a(a), b(b)
|
||||
{}
|
||||
@@ -53,7 +53,7 @@ class DependencyUnion : public ScriptValue {
|
||||
return unified( a->dependencies(ctx,dep), b->dependencies(ctx,dep));
|
||||
}
|
||||
virtual ScriptValueP makeIterator(ScriptValueP thisP) const {
|
||||
return unified(a->makeIterator(thisP), b->makeIterator(thisP));
|
||||
return unified(a->makeIterator(a), b->makeIterator(b));
|
||||
}
|
||||
virtual ScriptValueP dependencyMember(const String& name, const Dependency& dep) const {
|
||||
return unified(a->dependencyMember(name,dep), b->dependencyMember(name,dep));
|
||||
@@ -61,7 +61,7 @@ class DependencyUnion : public ScriptValue {
|
||||
virtual ScriptValueP dependencyName(const ScriptValue& container, const Dependency& dep) const {
|
||||
return unified(a->dependencyName(container,dep), b->dependencyName(container,dep));
|
||||
}
|
||||
private:
|
||||
private:
|
||||
ScriptValueP a, b;
|
||||
};
|
||||
|
||||
@@ -96,8 +96,8 @@ class ScriptMissingVariable : public ScriptValue {
|
||||
|
||||
// Utility class: a jump that has been postponed
|
||||
struct Context::Jump {
|
||||
const Instruction* target; ///< Target of the jump
|
||||
vector<ScriptValueP> stack_top; ///< The top part of the stack, everything local to the current call
|
||||
const Instruction* target; ///< Target of the jump
|
||||
vector<ScriptValueP> stack_top; ///< The top part of the stack, everything local to the current call
|
||||
vector<Binding> bindings; ///< The bindings made up to this point in the current scope
|
||||
};
|
||||
// an ordering on jumps by their target, lowest target = highest priority
|
||||
|
||||
@@ -316,11 +316,18 @@ SCRIPT_FUNCTION(to_title) {
|
||||
SCRIPT_RETURN(capitalize(input.Lower()));
|
||||
}
|
||||
|
||||
String reverse_string(String const& input) {
|
||||
// Note: std::reverse doesn't work because of unicode encoding stuff
|
||||
String reversed;
|
||||
for (auto it = input.rbegin(); it != input.rend(); ++it) {
|
||||
reversed += *it;
|
||||
}
|
||||
return reversed;
|
||||
}
|
||||
// reverse a string
|
||||
SCRIPT_FUNCTION(reverse) {
|
||||
SCRIPT_PARAM_C(String, input);
|
||||
reverse(input.begin(), input.end());
|
||||
SCRIPT_RETURN(input);
|
||||
SCRIPT_RETURN(reverse_string(input));
|
||||
}
|
||||
|
||||
// remove leading and trailing whitespace from a string
|
||||
@@ -370,12 +377,19 @@ SCRIPT_FUNCTION(regex_escape) {
|
||||
}
|
||||
|
||||
// sort/filter characters
|
||||
void sort_string(String& input) {
|
||||
vector<wxUniChar> chars;
|
||||
copy(input.begin(), input.end(), back_inserter(chars));
|
||||
sort(chars.begin(), chars.end());
|
||||
input.clear();
|
||||
for (auto c : chars) input += c;
|
||||
}
|
||||
SCRIPT_FUNCTION(sort_text) {
|
||||
SCRIPT_PARAM_C(String, input);
|
||||
SCRIPT_OPTIONAL_PARAM_C(String, order) {
|
||||
SCRIPT_RETURN(spec_sort(order, input));
|
||||
} else {
|
||||
sort(input.begin(), input.end());
|
||||
sort_string(input);
|
||||
SCRIPT_RETURN(input);
|
||||
}
|
||||
}
|
||||
@@ -432,7 +446,6 @@ SCRIPT_FUNCTION(remove_tags) {
|
||||
|
||||
// ----------------------------------------------------------------------------- : Collection stuff
|
||||
|
||||
|
||||
/// position of some element in a vector
|
||||
/** 0 based index, -1 if not found */
|
||||
int position_in_vector(const ScriptValueP& of, const ScriptValueP& in, const ScriptValueP& order_by, const ScriptValueP& filter) {
|
||||
@@ -450,7 +463,7 @@ int position_in_vector(const ScriptValueP& of, const ScriptValueP& in, const Scr
|
||||
}
|
||||
} else {
|
||||
// unordered position
|
||||
ScriptValueP it = in->makeIterator(in);
|
||||
ScriptValueP it = in->makeIterator();
|
||||
int i = 0;
|
||||
while (ScriptValueP v = it->next()) {
|
||||
if (equal(of, v)) return i;
|
||||
@@ -473,7 +486,7 @@ ScriptValueP sort_script(Context& ctx, const ScriptValueP& list, ScriptValue& or
|
||||
if (list_t == SCRIPT_STRING) {
|
||||
// sort a string
|
||||
String s = list->toString();
|
||||
sort(s.begin(), s.end());
|
||||
sort_string(s);
|
||||
if (remove_duplicates) {
|
||||
s.erase( unique(s.begin(), s.end()), s.end() );
|
||||
}
|
||||
@@ -483,7 +496,7 @@ ScriptValueP sort_script(Context& ctx, const ScriptValueP& list, ScriptValue& or
|
||||
ScriptObject<Set*>* set = dynamic_cast<ScriptObject<Set*>*>(list.get());
|
||||
// sort a collection
|
||||
vector<pair<String,ScriptValueP> > values;
|
||||
ScriptValueP it = list->makeIterator(list);
|
||||
ScriptValueP it = list->makeIterator();
|
||||
while (ScriptValueP v = it->next()) {
|
||||
ctx.setVariable(set ? _("card") : _("input"), v);
|
||||
values.push_back(make_pair(order_by.eval(ctx)->toString(), v));
|
||||
@@ -558,7 +571,7 @@ SCRIPT_FUNCTION(filter_list) {
|
||||
SCRIPT_PARAM_C(ScriptValueP, filter);
|
||||
// filter a collection
|
||||
ScriptCustomCollectionP ret(new ScriptCustomCollection());
|
||||
ScriptValueP it = input->makeIterator(input);
|
||||
ScriptValueP it = input->makeIterator();
|
||||
while (ScriptValueP v = it->next()) {
|
||||
ctx.setVariable(SCRIPT_VAR_input, v);
|
||||
if (*filter->eval(ctx)) {
|
||||
@@ -581,7 +594,7 @@ SCRIPT_FUNCTION(random_shuffle) {
|
||||
SCRIPT_PARAM_C(ScriptValueP, input);
|
||||
// convert to CustomCollection
|
||||
ScriptCustomCollectionP ret(new ScriptCustomCollection());
|
||||
ScriptValueP it = input->makeIterator(input);
|
||||
ScriptValueP it = input->makeIterator();
|
||||
while (ScriptValueP v = it->next()) {
|
||||
ret->value.push_back(v);
|
||||
}
|
||||
@@ -620,7 +633,7 @@ SCRIPT_FUNCTION(random_select_many) {
|
||||
throw ScriptError(String::Format(_("Can not select %d items from a collection conaining only %d items"), count, input->itemCount()));
|
||||
}
|
||||
// transfer all to ret and shuffle
|
||||
ScriptValueP it = input->makeIterator(input);
|
||||
ScriptValueP it = input->makeIterator();
|
||||
while (ScriptValueP v = it->next()) {
|
||||
ret->value.push_back(v);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ SCRIPT_FUNCTION(new_card) {
|
||||
CardP new_card = intrusive(new Card(*game));
|
||||
// set field values
|
||||
SCRIPT_PARAM(ScriptValueP, input);
|
||||
ScriptValueP it = input->makeIterator(input);
|
||||
ScriptValueP it = input->makeIterator();
|
||||
ScriptValueP key;
|
||||
while (ScriptValueP v = it->next(&key)) {
|
||||
assert(key);
|
||||
|
||||
@@ -384,7 +384,7 @@ SCRIPT_FUNCTION(count_chosen) {
|
||||
SCRIPT_RETURN(0);
|
||||
} else {
|
||||
int count = 1;
|
||||
FOR_EACH(c, input) if (c == _(',')) ++count;
|
||||
FOR_EACH_CONST(c, input) if (c == _(',')) ++count;
|
||||
SCRIPT_RETURN(count);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ class ScriptableImage {
|
||||
/// Is there a scripted image set?
|
||||
inline bool isScripted() const { return script; }
|
||||
/// Is there an image generator available?
|
||||
inline bool isReady() const { return value; }
|
||||
inline bool isReady() const { return (bool)value; }
|
||||
/// Is there an image set?
|
||||
inline bool isSet() const { return script || value; }
|
||||
|
||||
|
||||
+20
-20
@@ -22,32 +22,32 @@ DECLARE_POINTER_TYPE(Script);
|
||||
*/
|
||||
enum InstructionType
|
||||
// Basic
|
||||
{ I_NOP = 0 ///< arg = * : no operation, used as placeholder for extra data values
|
||||
, I_PUSH_CONST = 1 ///< arg = const val : push a constant onto the stack
|
||||
, I_JUMP = 2 ///< arg = address : move the instruction pointer to the given position
|
||||
, I_JUMP_IF_NOT = 3 ///< arg = address : move the instruction pointer if the top of the stack is false
|
||||
, I_JUMP_SC_AND = 19 ///< arg = address : (short-circuiting and) jump and don't pop if the top of the stack is false
|
||||
, I_JUMP_SC_OR = 20 ///< arg = address : (short-circuiting or) jump and don't pop if the top of the stack is true
|
||||
{ I_NOP = 0 ///< arg = * : no operation, used as placeholder for extra data values
|
||||
, I_PUSH_CONST = 1 ///< arg = const val : push a constant onto the stack
|
||||
, I_JUMP = 2 ///< arg = address : move the instruction pointer to the given position
|
||||
, I_JUMP_IF_NOT = 3 ///< arg = address : move the instruction pointer if the top of the stack is false
|
||||
, I_JUMP_SC_AND = 19 ///< arg = address : (short-circuiting and) jump and don't pop if the top of the stack is false
|
||||
, I_JUMP_SC_OR = 20 ///< arg = address : (short-circuiting or) jump and don't pop if the top of the stack is true
|
||||
// Variables
|
||||
, I_GET_VAR = 4 ///< arg = var : find a variable, push its value onto the stack, it is an error if the variable is not found
|
||||
, I_SET_VAR = 5 ///< arg = var : assign the top value from the stack to a variable (doesn't pop)
|
||||
, I_GET_VAR = 4 ///< arg = var : find a variable, push its value onto the stack, it is an error if the variable is not found
|
||||
, I_SET_VAR = 5 ///< arg = var : assign the top value from the stack to a variable (doesn't pop)
|
||||
// Objects
|
||||
, I_MEMBER_C = 6 ///< arg = const name : finds a member of the top of the stack replaces the top of the stack with the member
|
||||
, I_LOOP = 7 ///< arg = address : loop over the elements of an iterator, which is the *second* element of the stack (this allows for combing the results of multiple iterations)
|
||||
///< at the end performs a jump and pops the iterator. note: The second element of the stack must be an iterator!
|
||||
, I_LOOP_WITH_KEY = 8 ///< arg = address : loop, but also pushing the key
|
||||
, I_MEMBER_C = 6 ///< arg = const name : finds a member of the top of the stack replaces the top of the stack with the member
|
||||
, I_LOOP = 7 ///< arg = address : loop over the elements of an iterator, which is the *second* element of the stack (this allows for combing the results of multiple iterations)
|
||||
///< at the end performs a jump and pops the iterator. note: The second element of the stack must be an iterator!
|
||||
, I_LOOP_WITH_KEY = 8 ///< arg = address : loop, but also pushing the key
|
||||
, I_MAKE_OBJECT = 9 ///< arg = int : make a list/map with n elements, pops 2n values of the stack, n key/value pairs
|
||||
// Functions
|
||||
, I_CALL = 10 ///< arg = int, n*var : call the top item of the stack, with the given number of arguments (set with SET_VAR, but in the activation record of the call)
|
||||
, I_CALL = 10 ///< arg = int, n*var : call the top item of the stack, with the given number of arguments (set with SET_VAR, but in the activation record of the call)
|
||||
, I_CLOSURE = 11 ///< arg = int, n*var : construct a call closure object with the given arguments
|
||||
, I_TAILCALL = 12 ///< arg = int, n*var : perform a tail call - like I_CALL, except faster
|
||||
, I_TAILCALL = 12 ///< arg = int, n*var : perform a tail call - like I_CALL, except faster
|
||||
// Simple instructions
|
||||
, I_UNARY = 13 ///< arg = 1ary instr : pop 1 value, apply a function, push the result
|
||||
, I_BINARY = 14 ///< arg = 2ary instr : pop 2 values, apply a function, push the result
|
||||
, I_TERNARY = 15 ///< arg = 3ary instr : pop 3 values, apply a function, push the result
|
||||
, I_QUATERNARY = 16 ///< arg = 4ary instr : pop 4 values, apply a function, push the result
|
||||
, I_DUP = 17 ///< arg = int : duplicate the k-from-top element of the stack
|
||||
, I_POP = 18 ///< arg = * : pop the top value off the stack.
|
||||
, I_UNARY = 13 ///< arg = 1ary instr : pop 1 value, apply a function, push the result
|
||||
, I_BINARY = 14 ///< arg = 2ary instr : pop 2 values, apply a function, push the result
|
||||
, I_TERNARY = 15 ///< arg = 3ary instr : pop 3 values, apply a function, push the result
|
||||
, I_QUATERNARY = 16 ///< arg = 4ary instr : pop 4 values, apply a function, push the result
|
||||
, I_DUP = 17 ///< arg = int : duplicate the k-from-top element of the stack
|
||||
, I_POP = 18 ///< arg = * : pop the top value off the stack.
|
||||
};
|
||||
|
||||
/// Types of unary instructions (taking one argument from the stack)
|
||||
|
||||
+13
-19
@@ -75,8 +75,8 @@ bool equal(const ScriptValueP& a, const ScriptValueP& b) {
|
||||
} else if (at == SCRIPT_COLLECTION && bt == SCRIPT_COLLECTION) {
|
||||
// compare each element
|
||||
if (a->itemCount() != b->itemCount()) return false;
|
||||
ScriptValueP a_it = a->makeIterator(a);
|
||||
ScriptValueP b_it = b->makeIterator(b);
|
||||
ScriptValueP a_it = a->makeIterator();
|
||||
ScriptValueP b_it = b->makeIterator();
|
||||
while (true) {
|
||||
ScriptValueP a_v = a_it->next();
|
||||
ScriptValueP b_v = b_it->next();
|
||||
@@ -115,7 +115,7 @@ ScriptValueP ScriptDelayedError::getMember(const String&) const
|
||||
ScriptValueP ScriptDelayedError::dependencyMember(const String&, const Dependency&) const { return intrusive(new ScriptDelayedError(error)); }
|
||||
ScriptValueP ScriptDelayedError::do_eval(Context&, bool) const { return intrusive(new ScriptDelayedError(error)); }
|
||||
ScriptValueP ScriptDelayedError::dependencies(Context&, const Dependency&) const { return intrusive(new ScriptDelayedError(error)); }
|
||||
ScriptValueP ScriptDelayedError::makeIterator(const ScriptValueP& thisP) const { return thisP; }
|
||||
ScriptValueP ScriptDelayedError::makeIterator(const ScriptValueP& thisP) const { return thisP ? thisP : intrusive(new ScriptDelayedError(error)); }
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------- : Iterators
|
||||
@@ -279,7 +279,8 @@ class ScriptString : public ScriptValue {
|
||||
}
|
||||
virtual operator wxDateTime() const {
|
||||
wxDateTime date;
|
||||
if (!date.ParseDateTime(value.c_str())) {
|
||||
String::const_iterator end;
|
||||
if (!date.ParseDateTime(value,&end) || end != value.end()) {
|
||||
throw ScriptErrorConversion(value, typeName(), _TYPE_("date"));
|
||||
}
|
||||
return date;
|
||||
@@ -386,13 +387,7 @@ ScriptValueP script_nil(new ScriptNil);
|
||||
String ScriptCollectionBase::toCode() const {
|
||||
String ret = _("[");
|
||||
bool first = true;
|
||||
#ifdef USE_INTRUSIVE_PTR
|
||||
// we can just turn this into a ScriptValueP
|
||||
// TODO: remove thisP alltogether
|
||||
ScriptValueP it = makeIterator(ScriptValueP(const_cast<ScriptValue*>(static_cast<const ScriptValue*>(this))));
|
||||
#else
|
||||
#error "makeIterator needs a ScriptValueP :("
|
||||
#endif
|
||||
ScriptValueP it = makeIterator();
|
||||
while (ScriptValueP v = it->next()) {
|
||||
if (!first) ret += _(",");
|
||||
first = false;
|
||||
@@ -407,9 +402,9 @@ String ScriptCollectionBase::toCode() const {
|
||||
|
||||
// Iterator over a custom collection
|
||||
class ScriptCustomCollectionIterator : public ScriptIterator {
|
||||
public:
|
||||
ScriptCustomCollectionIterator(ScriptCustomCollectionP col)
|
||||
: col(col), pos(0), it(col->key_value.begin()) {}
|
||||
public:
|
||||
ScriptCustomCollectionIterator(ScriptCustomCollection const* col, ScriptValueP const& col_owned)
|
||||
: col(col), col_owned(col_owned), pos(0), it(col->key_value.begin()) {}
|
||||
virtual ScriptValueP next(ScriptValueP* key_out) {
|
||||
if (pos < col->value.size()) {
|
||||
if (key_out) *key_out = to_script((int)pos);
|
||||
@@ -421,8 +416,9 @@ class ScriptCustomCollectionIterator : public ScriptIterator {
|
||||
return ScriptValueP();
|
||||
}
|
||||
}
|
||||
private:
|
||||
ScriptCustomCollectionP col;
|
||||
private:
|
||||
ScriptCustomCollection const* col;
|
||||
ScriptValueP col_owned; // own the collection so it doesn't get deleted
|
||||
size_t pos;
|
||||
map<String,ScriptValueP>::const_iterator it;
|
||||
};
|
||||
@@ -443,9 +439,7 @@ ScriptValueP ScriptCustomCollection::getIndex(int index) const {
|
||||
}
|
||||
}
|
||||
ScriptValueP ScriptCustomCollection::makeIterator(const ScriptValueP& thisP) const {
|
||||
return intrusive(new ScriptCustomCollectionIterator(
|
||||
static_pointer_cast<ScriptCustomCollection>(thisP)
|
||||
));
|
||||
return intrusive(new ScriptCustomCollectionIterator(this, thisP));
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Concat collection
|
||||
|
||||
@@ -108,10 +108,12 @@ class ScriptValue : public IntrusivePtrBaseWithDelete {
|
||||
* Alternatively, the closure may be modified in place.
|
||||
*/
|
||||
virtual ScriptValueP simplifyClosure(ScriptClosure&) const;
|
||||
|
||||
|
||||
/// Return an iterator for the current collection, an iterator is a value that has next()
|
||||
/** thisP can be used to prevent destruction of the collection */
|
||||
virtual ScriptValueP makeIterator(const ScriptValueP& thisP) const;
|
||||
/** thisP is a shared_ptr for this collection, needed for the iterator to take ownership of it.
|
||||
* It can be null if the iterator always lives shorter than the collection.
|
||||
*/
|
||||
virtual ScriptValueP makeIterator(const ScriptValueP& thisP = ScriptValueP()) const;
|
||||
/// Return the next item for this iterator, or ScriptValueP() if there is no such item
|
||||
/** If key_out != 0, then it will recieve the key of the item */
|
||||
virtual ScriptValueP next(ScriptValueP* key_out = nullptr);
|
||||
|
||||
Reference in New Issue
Block a user