summaryrefslogtreecommitdiff
path: root/src/compat/attr.hpp
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2015-01-03 21:50:12 -0800
committerBen Longbons <b.r.longbons@gmail.com>2015-01-03 21:50:12 -0800
commit4c91abd6a020ee030114ae3f22d8f6066e7528be (patch)
tree9f76256eabe4900a7eef6cbb94b7ed2378b93f48 /src/compat/attr.hpp
parent0a202555d2e12866b3619af92f50cb38ea4adb12 (diff)
parent711680d652a8db17c1b91428b6d6835f30dfb4fd (diff)
downloadtmwa-4c91abd6a020ee030114ae3f22d8f6066e7528be.tar.gz
tmwa-4c91abd6a020ee030114ae3f22d8f6066e7528be.tar.bz2
tmwa-4c91abd6a020ee030114ae3f22d8f6066e7528be.tar.xz
tmwa-4c91abd6a020ee030114ae3f22d8f6066e7528be.zip
Merge remote-tracking branch 'origin/hotfix'
Conflicts: src/map/chrif.cpp
Diffstat (limited to 'src/compat/attr.hpp')
-rw-r--r--src/compat/attr.hpp28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/compat/attr.hpp b/src/compat/attr.hpp
index 5322a14..9ddf654 100644
--- a/src/compat/attr.hpp
+++ b/src/compat/attr.hpp
@@ -1,7 +1,7 @@
#pragma once
// attr.hpp - Attributes.
//
-// Copyright © 2013 Ben Longbons <b.r.longbons@gmail.com>
+// Copyright © 2013-2014 Ben Longbons <b.r.longbons@gmail.com>
//
// This file is part of The Mana World (Athena server)
//
@@ -31,7 +31,27 @@ namespace tmwa
#define JOIN(a, b) a##b
-#define WITH_VAR(ty, var, expr) \
- for (bool JOIN(var, _guard) = true; JOIN(var, _guard); ) \
- for (ty var = expr; JOIN(var, _guard); JOIN(var, _guard) = false)
+// first loop:
+// declare flag 'guard' (initially true)
+// declare flag 'broken' (initially false)
+// condition is 'guard' must be true, which is the case only for the first iteration
+// post checks 'broken' and if set, break the loop
+// second loop:
+// declare public 'var' variable
+// condition is that 'guard' must be true
+// post sets 'guard' to false to make this loop run only once
+// third loop:
+// enable broken flag; it will remain set if 'break' is in the loop
+// condition is that 'broken' must be true
+// post sets 'broken' to false, which then fails the condition
+// if user has a 'break' inside, then 'broken' will be true
+// in either case, go back to the second loop's post
+#define WITH_VAR_INLOOP(ty, var, expr) \
+ for (bool JOIN(var, _guard) = true, JOIN(var, _broken) = false; JOIN(var, _guard); ({if (JOIN(var, _broken)) { break; } })) \
+ for (ty var = expr; JOIN(var, _guard); JOIN(var, _guard) = false) \
+ for (JOIN(var, _broken) = true; JOIN(var, _broken); JOIN(var, _broken) = false)
+#define WITH_VAR_NOLOOP(ty, var, expr) \
+ for (bool JOIN(var, _guard) = true, JOIN(var, _broken) = false; JOIN(var, _guard); ({if (JOIN(var, _broken)) {abort();} })) \
+ for (ty var = expr; JOIN(var, _guard); JOIN(var, _guard) = false) \
+ for (JOIN(var, _broken) = true; JOIN(var, _broken); JOIN(var, _broken) = false)
} // namespace tmwa