/simpletypesystem/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk

« back to all changes in this revision

Viewing changes to src/utils.h

  • Committer: Gustav Hartvigsson
  • Date: 2015-04-10 21:36:10 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20150410213610-r1q96ym4nmulpax9
* Added a few skeletal functions to Callback.h
* Re-wrote parts of SDynamicArray to be more sane.
  * removed s_dynamic_array_len() and s_dynamic_array_add()
  * added s_dynamic_array_set() and s_dynamic_array_last_item()
  * use calloc instead of malloc.
* added unsubscribe function to SGlobalNotify.
* Added decumentation in Interface.h
* Made s_dbg_print() more helpful.

-- Testing --
* Made test_case() macro more useful.
* added tests for the dynamic array.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
BEGIN_DECLS
32
32
 
 
33
/** @file
 
34
 * A collect of utility functions.
 
35
 */
 
36
 
33
37
/**
34
38
 * Creats a new C string with the correct length from a long string.
35
39
 * This may be a costly operation.
85
89
#define s_err_print(p, ...)\
86
90
  fprintf (stderr, RED "[ERR] " p RESET "\n", ##__VA_ARGS__)
87
91
 
88
 
 
89
92
#if DEBUG
90
93
/**
91
94
 * debug_print is a function that only prints if compiled with the debug
92
95
 * flag not unset.
93
96
 */
94
 
#  define s_dbg_print(M, ...)\
95
 
    fprintf (stderr, YELLOW "[DEBUG] " M RESET "\n", ##__VA_ARGS__)
 
97
  #define s_dbg_print(M, ...)\
 
98
    fprintf (stdout, YELLOW "[DEBUG][%s:%d] " M RESET "\n", __FILE__, __LINE__, ##__VA_ARGS__)
96
99
#else
97
 
#  define s_dbg_print(M, ...) 
 
100
  #define s_dbg_print(M, ...) 
98
101
#endif
99
102
 
 
103
/**
 
104
 * Round a up a number to a multiple of an other.
 
105
 *
 
106
 * @param num The number to round up.
 
107
 * @param multiple The multiple to round up to.
 
108
 *
 
109
 * See: http://stackoverflow.com/a/9194117
 
110
 */
 
111
#define round_up(num, multiple) (((num + multiple - 1) / multiple) * multiple)
 
112
 
100
113
BEGIN_DECLS
101
114
 
102
115
#endif