operators.h 2.52 KB
Newer Older
thomas.forbriger's avatar
thomas.forbriger committed
1
2
3
4
5
/*! \file operators.h
 * \brief provide operators for iteratable objects (prototypes)
 * 
 * ----------------------------------------------------------------------------
 * 
thomas.forbriger's avatar
thomas.forbriger committed
6
 * $Id: operators.h,v 1.3 2004-02-10 11:45:28 tforb Exp $
thomas.forbriger's avatar
thomas.forbriger committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 * \author Thomas Forbriger
 * \date 10/02/2004
 * 
 * provide operators for iteratable objects (prototypes)
 * 
 * Copyright (c) 2004 by Thomas Forbriger (BFO Schiltach) 
 * 
 * REVISIONS and CHANGES 
 *  - 10/02/2004   V1.0   Thomas Forbriger
 * 
 * ============================================================================
 */

// include guard
thomas.forbriger's avatar
thomas.forbriger committed
21
#ifndef AFF_OPERATORS_CLASS
thomas.forbriger's avatar
thomas.forbriger committed
22
23
24
25
#error "never ever inlcude this from your code!"
#endif
#ifndef AFF_OPERATORS_CONSTCLASS
#error "definition of container of const is missing!"
thomas.forbriger's avatar
thomas.forbriger committed
26
#endif
thomas.forbriger's avatar
thomas.forbriger committed
27

thomas.forbriger's avatar
thomas.forbriger committed
28
#include<aff/iterator.h>
thomas.forbriger's avatar
thomas.forbriger committed
29

thomas.forbriger's avatar
thomas.forbriger committed
30
namespace aff {
thomas.forbriger's avatar
thomas.forbriger committed
31
32
33
34
  
#define AFF_OPERATORS_TEMPAR T
#define AFF_OPERATORS_CONT AFF_OPERATORS_CLASS< AFF_OPERATORS_TEMPAR >
#define AFF_OPERATORS_CONSTCONT AFF_OPERATORS_CONSTCLASS< AFF_OPERATORS_TEMPAR >
thomas.forbriger's avatar
thomas.forbriger committed
35

thomas.forbriger's avatar
thomas.forbriger committed
36
37
38
39
40
41
42
43
#define AFF_OPERATORS_UNOP( CONT, OP ) \
  template<class AFF_OPERATORS_TEMPAR > \
  CONT& operator OP ## =(CONT& container, \
                         typename CONT::Tconst_reference value) \
  { \
    for (aff::Iterator< CONT > i(container); i.valid(); ++i) \
    { (*i) OP ## = value; } \
    return(container); \
thomas.forbriger's avatar
thomas.forbriger committed
44
  }
thomas.forbriger's avatar
thomas.forbriger committed
45

thomas.forbriger's avatar
thomas.forbriger committed
46
47
48
49
50
51
52
53
54
#define AFF_OPERATORS_BINOP( RETCONT, INCONT, OP ) \
  template<class AFF_OPERATORS_TEMPAR > \
  RETCONT operator OP(const INCONT& container, \
                       typename INCONT::Tconst_reference value) \
  { \
    RETCONT retval; \
    retval.copyin(container); \
    retval OP ## = value; \
    return(retval); \
thomas.forbriger's avatar
thomas.forbriger committed
55
  }
thomas.forbriger's avatar
thomas.forbriger committed
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87

#define AFF_OPERATORS_THEUNOP( OP ) \
  AFF_OPERATORS_UNOP( AFF_OPERATORS_CONT , OP )
  AFF_OPERATORS_THEUNOP( + )
  AFF_OPERATORS_THEUNOP( * )
  AFF_OPERATORS_THEUNOP( / )
  AFF_OPERATORS_THEUNOP( - )
#undef AFF_OPERATORS_THEUNOP

#define AFF_OPERATORS_THEBINOP( OP ) \
  AFF_OPERATORS_BINOP( AFF_OPERATORS_CONT , AFF_OPERATORS_CONSTCONT, OP )
  AFF_OPERATORS_THEBINOP( + )
  AFF_OPERATORS_THEBINOP( * )
  AFF_OPERATORS_THEBINOP( / )
  AFF_OPERATORS_THEBINOP( - )
#undef AFF_OPERATORS_THEBINOP

  /*
#define AFF_OPERATORS_THEBINOP( OP ) \
  AFF_OPERATORS_BINOP( AFF_OPERATORS_CONT , AFF_OPERATORS_CONT, OP )
  AFF_OPERATORS_THEBINOP( + )
  AFF_OPERATORS_THEBINOP( * )
  AFF_OPERATORS_THEBINOP( / )
  AFF_OPERATORS_THEBINOP( - )
#undef AFF_OPERATORS_THEBINOP
*/

#undef AFF_OPERATORS_UNOP
#undef AFF_OPERATORS_BINOP
#undef AFF_OPERATORS_CONSTCONT
#undef AFF_OPERATORS_CONT
#undef AFF_OPERATORS_TEMPAR
thomas.forbriger's avatar
thomas.forbriger committed
88
}
thomas.forbriger's avatar
thomas.forbriger committed
89
90

/* ----- END OF operators.h ----- */