Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
VarArg.h
1 /*
2  * $Id$
3  * Copyright (c) 2005, IRIT-UPS Corporation.
4  *
5  * util.VarArg.h -- VarArg class interface.
6  */
7 #ifndef ELM_UTIL_VARARG_H
8 #define ELM_UTIL_VARARG_H
9 
10 #include <stdarg.h>
11 
12 namespace elm {
13 
14 // Macros
15 #define VARARG_BEGIN(name, arg) \
16  { \
17  va_list __args; \
18  va_start(__args, arg); \
19  elm::VarArg name(__args);
20 #define VARARG_END \
21  va_end(__args); \
22  }
23 
24 // VarArg class
25 class VarArg {
26  va_list& _args;
27 public:
28  inline VarArg(va_list& args);
29  inline VarArg(const VarArg& args);
30  template <class T> T next(void);
31  inline va_list& args(void);
32 };
33 
34 // Inlines
35 inline VarArg::VarArg(va_list& args): _args(args) {
36 }
37 
38 inline VarArg::VarArg(const VarArg& args): _args(args._args) {
39 }
40 
41 template <class T>
42 T VarArg::next(void) {
43  return va_arg(_args, T);
44 }
45 
46 inline va_list& VarArg::args(void) {
47  return _args;
48 }
49 
50 // Useful overload
51 template <> inline bool VarArg::next(void) {
52  return (bool)va_arg(_args, int);
53 };
54 
55 template <> inline char VarArg::next(void) {
56  return (char)va_arg(_args, int);
57 };
58 
59 template <> inline short VarArg::next(void) {
60  return (short)va_arg(_args, int);
61 };
62 
63 template <> inline unsigned char VarArg::next(void) {
64  return (unsigned char)va_arg(_args, unsigned int);
65 };
66 
67 template <> inline unsigned short VarArg::next(void) {
68  return (unsigned short)va_arg(_args, unsigned int);
69 };
70 
71 } // elm
72 
73 #endif // ELM_UTIL_VARARG_H
elm::VarArg::args
va_list & args(void)
Definition: VarArg.h:46
elm
Definition: adapter.h:26
elm::VarArg::VarArg
VarArg(va_list &args)
Definition: VarArg.h:35
elm::VarArg
Definition: VarArg.h:25
elm::VarArg::next
T next(void)
Definition: VarArg.h:42