AFF --- A container for numbers (array) by Friederich and Forbriger.
operators.h
Go to the documentation of this file.
1 
38 // include guard
39 #ifndef AFF_OPERATORS_CLASS
40 #error "never ever inlcude this from your code!"
41 #endif
42 
43 #ifndef AFF_OPERATORS_CONSTCLASS
44 #error "definition of container of const is missing!"
45 #endif
46 
47 #include<aff/iterator.h>
48 
49 namespace aff {
50 
70 #define AFF_OPERATORS_TEMPAR T
71 #define AFF_OPERATORS_CONT AFF_OPERATORS_CLASS< AFF_OPERATORS_TEMPAR >
72 #define AFF_OPERATORS_CONSTCONT AFF_OPERATORS_CONSTCLASS< AFF_OPERATORS_TEMPAR >
73 
74 
75 /*----------------------------------------------------------------------*/
76 
80 #define AFF_OPERATORS_UNOP( CONT, OP ) \
81  template<class AFF_OPERATORS_TEMPAR > \
82  const CONT& operator OP ## =(const CONT& container, \
83  typename CONT::Tconst_reference value) \
84  { \
85  for (aff::Iterator< CONT > i(container); i.valid(); ++i) \
86  { (*i) OP ## = value; } \
87  return(container); \
88  }
89 
90 /*----------------------------------------------------------------------*/
91 
95 #define AFF_OPERATORS_BINOP( RETCONT, INCONT, OP ) \
96  template<class AFF_OPERATORS_TEMPAR > \
97  RETCONT operator OP(const INCONT& container, \
98  typename INCONT::Tconst_reference value) \
99  { \
100  RETCONT retval(container.shape()); \
101  aff::Browser< typename INCONT::Tcontainer > i(container); \
102  aff::Iterator< typename RETCONT::Tcontainer > o(retval); \
103  while ( i.valid() && o. valid() ) \
104  { (*o) = (*i) OP value; ++o; ++i; } \
105  return(retval); \
106  } \
107  template<class AFF_OPERATORS_TEMPAR > \
108  RETCONT operator OP(typename INCONT::Tconst_reference value, \
109  const INCONT& container) \
110  { return( container OP value ); }
111 
112 /*----------------------------------------------------------------------*/
113 
117 #define AFF_OPERATORS_UNOPB( RETCONT, INCONT, OP ) \
118  template<class A , class B > \
119  RETCONT< A >& operator OP ## =(RETCONT< A >& container1, \
120  const INCONT< B >& container2) \
121  { \
122  aff::Iterator< RETCONT< A > > i1(container1); \
123  aff::Browser< INCONT< B > > i2(container2); \
124  while ( i1.valid() && i2.valid() ) \
125  { (*i1) OP ## = (*i2); ++i1; ++i2; } \
126  return(container1); \
127  }
128 
129 /*----------------------------------------------------------------------*/
130 
134 #define AFF_OPERATORS_BINOPB( RETCONT, INCONT, OP ) \
135  template<class A , class B > \
136  RETCONT< A > operator OP(const INCONT< A >& container1, \
137  const INCONT< B >& container2) \
138  { \
139  RETCONT< A > retval(container1.shape()); \
140  retval=A(0); \
141  aff::Browser< INCONT< A > > i1(container1); \
142  aff::Browser< INCONT< B > > i2(container2); \
143  aff::Iterator< RETCONT< A > > o(retval); \
144  while ( i1.valid() && o.valid() && i2.valid() ) \
145  { (*o) = (*i1) OP (*i2); ++o; ++i1; ++i2; } \
146  return(retval); \
147  }
148 
149 /*======================================================================*/
150 
156 #define AFF_OPERATORS_THEUNOP( OP ) \
157  AFF_OPERATORS_UNOP( AFF_OPERATORS_CONT , OP )
163 #undef AFF_OPERATORS_THEUNOP
164 
170 #define AFF_OPERATORS_THEBINOP( OP ) \
171  AFF_OPERATORS_BINOP( AFF_OPERATORS_CONT , AFF_OPERATORS_CONSTCONT, OP )
177 #undef AFF_OPERATORS_THEBINOP
178 
184 #define AFF_OPERATORS_THEBINOP( OP ) \
185  AFF_OPERATORS_BINOPB( AFF_OPERATORS_CLASS , AFF_OPERATORS_CONSTCLASS , OP )
191 #undef AFF_OPERATORS_THEBINOP
192 
198 #define AFF_OPERATORS_THEUNOP( OP ) \
199  AFF_OPERATORS_UNOPB( AFF_OPERATORS_CLASS , AFF_OPERATORS_CONSTCLASS , OP )
205 #undef AFF_OPERATORS_THEUNOP
206 
207 #undef AFF_OPERATORS_UNOP
208 #undef AFF_OPERATORS_BINOP
209 #undef AFF_OPERATORS_BINOPB
210 #undef AFF_OPERATORS_CONSTCONT
211 #undef AFF_OPERATORS_CONT
212 #undef AFF_OPERATORS_TEMPAR
213 }
214 
215 /* ----- END OF operators.h ----- */
Root namespace of library.
Definition: array.h:148
#define AFF_OPERATORS_THEUNOP(OP)
unary operatorsThis makes use of AFF_OPERATORS_THEUNOP and AFF_OPERATORS_UNOP
Definition: operators.h:198
#define AFF_OPERATORS_THEBINOP(OP)
binary operatorsThis makes use of AFF_OPERATORS_THEBINOP and AFF_OPERATORS_BINOP
Definition: operators.h:184
Define the iterator class template (prototypes)