amino
Lightweight Robot Utility Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
getset.h
1 /* -*- mode: C; c-basic-offset: 4 -*- */
2 /* ex: set shiftwidth=4 tabstop=4 expandtab: */
3 /*
4  * Copyright (c) 2015, Rice University
5  * All rights reserved.
6  *
7  * Author(s): Neil T. Dantam <ntd@gatech.edu>
8  * Georgia Tech Humanoid Robotics Lab
9  * Under Direction of Prof. Mike Stilman <mstilman@cc.gatech.edu>
10  *
11  *
12  * This file is provided under the following "BSD-style" License:
13  *
14  *
15  * Redistribution and use in source and binary forms, with or
16  * without modification, are permitted provided that the following
17  * conditions are met:
18  *
19  * * Redistributions of source code must retain the above copyright
20  * notice, this list of conditions and the following disclaimer.
21  *
22  * * Redistributions in binary form must reproduce the above
23  * copyright notice, this list of conditions and the following
24  * disclaimer in the documentation and/or other materials provided
25  * with the distribution.
26  *
27  * * Neither the name of the Rice University nor the names of its
28  * contributors may be used to endorse or promote products derived
29  * from this software without specific prior written permission.
30  *
31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
32  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
33  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
34  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
35  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
36  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
37  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
38  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
39  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
40  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
41  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
42  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
43  * POSSIBILITY OF SUCH DAMAGE.
44  *
45  */
46 
47 #ifndef AMINO_GETSET_H
48 #define AMINO_GETSET_H
49 
50 #define AA_DEC_SETTER( struct_type, type, field_name ) \
51  AA_API void \
52  struct_type ## _set_ ## field_name( struct struct_type *obj, \
53  type field_name )
54 
55 
56 #define AA_DEC_VEC_SETTER( struct_type, field_name ) \
57  AA_API void \
58  struct_type ## _set_ ## field_name( struct struct_type *obj, \
59  const double field_name[3] )
60 
61 #define AA_DEC_VEC3_SETTER( struct_type, field_name, x, y, z) \
62  AA_API void \
63  struct_type ## _set_ ## field_name ## 3( struct struct_type *obj, \
64  double x, \
65  double y, \
66  double z )
67 
68 #define AA_DEF_SETTER( struct_type, field_type, field_name ) \
69  AA_DEC_SETTER( struct_type, field_type, field_name ) \
70  { \
71  obj->field_name = field_name; \
72  }
73 
74 #define AA_DEF_BOOL_SETTER( struct_type, field_name ) \
75  AA_DEC_SETTER( struct_type, int, field_name ) \
76  { \
77  obj->field_name = field_name ? 1 : 0; \
78  }
79 
80 #define AA_DEF_FLOAT_SETTER( struct_type, field_name ) \
81  AA_DEC_SETTER( struct_type, double, field_name ) \
82  { \
83  obj->field_name = (float)field_name; \
84  }
85 
86 #define AA_DEF_FLOAT3_SETTER( struct_type, field_name ) \
87  AA_DEC_VEC3_SETTER( struct_type, field_name, x, y, z ) \
88  { \
89  obj->field_name[0] = (float)x; \
90  obj->field_name[1] = (float)y; \
91  obj->field_name[2] = (float)z; \
92  } \
93  \
94  AA_DEC_VEC_SETTER( struct_type, field_name) \
95  { \
96  struct_type ## _set_ ## field_name ## 3( obj, \
97  field_name[0], \
98  field_name[1], \
99  field_name[2] ); \
100  }
101 
102 #define AA_DEF_VEC3_SETTER( struct_type, field_name ) \
103  AA_DEC_VEC3_SETTER( struct_type, field_name, x, y, z ) \
104  { \
105  obj->field_name[0] = x; \
106  obj->field_name[1] = y; \
107  obj->field_name[2] = z; \
108  } \
109  \
110  AA_DEC_VEC_SETTER( struct_type, field_name) \
111  { \
112  struct_type ## _set_ ## field_name ## 3( obj, \
113  field_name[0], \
114  field_name[1], \
115  field_name[2] ); \
116  }
117 
118 #define AA_DEF_GETTER( struct_type, field_type, field_name ) \
119  AA_API field_type \
120  struct_type ## _get_ ## field_name(const struct struct_type *obj) \
121  { \
122  return obj->field_name; \
123  }
124 
125 #endif /*AMINO_GETSET_H*/