summaryrefslogtreecommitdiff
path: root/src/common/db.h
diff options
context:
space:
mode:
authorFlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-06-02 20:19:40 +0000
committerFlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-06-02 20:19:40 +0000
commit85db2023cb033928a190ac7fa6f05b5d6cbad14a (patch)
treeb37ec6dab700ae4170968f10ccf0136242ee5f23 /src/common/db.h
parentc6f3f3b4d8e95e130af32ea24d3e30130688eab8 (diff)
downloadhercules-85db2023cb033928a190ac7fa6f05b5d6cbad14a.tar.gz
hercules-85db2023cb033928a190ac7fa6f05b5d6cbad14a.tar.bz2
hercules-85db2023cb033928a190ac7fa6f05b5d6cbad14a.tar.xz
hercules-85db2023cb033928a190ac7fa6f05b5d6cbad14a.zip
* Displaying op names instead of numbers in script engine errors.
* Fixed a bug introduced in the last rework of the fame ranking. * Created safestrncpy that ensures the string is nul-terminated. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@10667 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/common/db.h')
-rw-r--r--src/common/db.h77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/common/db.h b/src/common/db.h
index 992469f66..5c7d42d87 100644
--- a/src/common/db.h
+++ b/src/common/db.h
@@ -691,4 +691,81 @@ void* linkdb_search ( struct linkdb_node** head, void *key);
void* linkdb_erase ( struct linkdb_node** head, void *key);
void linkdb_final ( struct linkdb_node** head );
+
+
+/// Finds an entry in an array.
+/// ex: ARR_FIND(0, size, i, list[i] == target);
+///
+/// @param __start Starting index (ex: 0)
+/// @param __end End index (ex: size of the array)
+/// @param __var Index variable
+/// @param __cmp Expression that returns true when the target entry is found
+#define ARR_FIND(__start, __end, __var, __cmp) \
+ do{ \
+ for( (__var) = (__start); (__var) < (__end); ++(__var) ) \
+ if( __cmp ) \
+ break; \
+ }while(0)
+
+
+
+/// Moves an entry of the array.
+/// Use ARR_MOVERIGHT/ARR_MOVELEFT if __from and __to are direct numbers.
+/// ex: ARR_MOVE(i, 0, list, int);// move index i to index 0
+///
+///
+/// @param __from Initial index of the entry
+/// @param __end Target index of the entry
+/// @param __arr Array
+/// @param __type Type of entry
+#define ARR_MOVE(__from, __to, __arr, __type) \
+ do{ \
+ if( (__from) != (__to) ) \
+ { \
+ __type __backup__; \
+ memmove(&__backup__, (__arr)+(__from), sizeof(__type)); \
+ if( (__from) < (__to) ) \
+ memmove((__arr)+(__from), (__arr)+(__from)+1, ((__to)-(__from))*sizeof(__type)); \
+ else if( (__from) > (__to) ) \
+ memmove((__arr)+(__to)+1, (__arr)+(__to), ((__from)-(__to))*sizeof(__type)); \
+ memmove((__arr)+(__to), &__backup__, sizeof(__type)); \
+ } \
+ }while(0)
+
+
+
+/// Moves an entry of the array to the right.
+/// ex: ARR_MOVERIGHT(1, 4, list, int);// move index 1 to index 4
+///
+/// @param __from Initial index of the entry
+/// @param __end Target index of the entry
+/// @param __arr Array
+/// @param __type Type of entry
+#define ARR_MOVERIGHT(__from, __to, __arr, __type) \
+ do{ \
+ __type __backup__; \
+ memmove(&__backup__, (__arr)+(__from), sizeof(__type)); \
+ memmove((__arr)+(__from), (__arr)+(__from)+1, ((__to)-(__from))*sizeof(__type)); \
+ memmove((__arr)+(__to), &__backup__, sizeof(__type)); \
+ }while(0)
+
+
+
+/// Moves an entry of the array to the left.
+/// ex: ARR_MOVELEFT(3, 0, list, int);// move index 3 to index 0
+///
+/// @param __from Initial index of the entry
+/// @param __end Target index of the entry
+/// @param __arr Array
+/// @param __type Type of entry
+#define ARR_MOVELEFT(__from, __to, __arr, __type) \
+ do{ \
+ __type __backup__; \
+ memmove(&__backup__, (__arr)+(__from), sizeof(__type)); \
+ memmove((__arr)+(__to)+1, (__arr)+(__to), ((__from)-(__to))*sizeof(__type)); \
+ memmove((__arr)+(__to), &__backup__, sizeof(__type)); \
+ }while(0)
+
+
+
#endif /* _DB_H_ */