Tulip
4.2.0
Better Visualization Through Research
Main Page
Related Pages
Modules
Classes
Files
Examples
File List
All
Classes
Namespaces
Files
Functions
Variables
Enumerations
Enumerator
Properties
Groups
Pages
StoredType.h
1
/*
2
*
3
* This file is part of Tulip (www.tulip-software.org)
4
*
5
* Authors: David Auber and the Tulip development Team
6
* from LaBRI, University of Bordeaux 1 and Inria Bordeaux - Sud Ouest
7
*
8
* Tulip is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU Lesser General Public License
10
* as published by the Free Software Foundation, either version 3
11
* of the License, or (at your option) any later version.
12
*
13
* Tulip is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
* See the GNU General Public License for more details.
17
*
18
*/
19
///@cond DOXYGEN_HIDDEN
20
21
#ifndef _TLPRETURNTYPE_
22
#define _TLPRETURNTYPE_
23
24
#ifndef DOXYGEN_NOTFOR_DEVEL
25
namespace
tlp {
26
27
// the template below defines how are returned and stored
28
// the types of value a MutableContainer can managed
29
// basically a type is returned and stored by value
30
template
<
typename
TYPE>
31
struct
StoredType {
32
// the type of the stored value
33
typedef
TYPE Value;
34
// the type of the returned value
35
typedef
TYPE ReturnedValue;
36
// the type of a returned const value
37
typedef
TYPE ReturnedConstValue;
38
// indicates if a pointer to the value is stored
39
enum
{isPointer=0};
40
// simply get
41
inline
static
TYPE&
get
(
const
TYPE& val) {
42
return
(TYPE&) val;
43
}
44
// equallity test
45
inline
static
bool
equal(
const
TYPE& val1,
const
TYPE& val2) {
46
return
val2 == val1;
47
}
48
// cloning before storage
49
inline
static
Value clone(
const
TYPE& val) {
50
return
val;
51
}
52
// destruction of stored value
53
inline
static
void
destroy(Value) {}
54
// the default value of that type
55
inline
static
Value defaultValue() {
56
return
(Value) 0;
57
}
58
};
59
60
// non basic types are returned by reference
61
// and stored by pointer
62
// This last point enables a better management of the default value
63
// which can simply be flagged in storing a null pointer
64
// the macro below must be used to enable thies type of management
65
66
#ifdef TLP_NO_CONST_STORED_TYPE
67
#define DECL_STORED_STRUCT(T) \
68
template <> \
69
struct StoredType<T > { \
70
typedef T *Value; \
71
typedef T& ReturnedValue; \
72
typedef T ReturnedConstValue; \
73
\
74
enum {isPointer=1}; \
75
\
76
inline static T& get(const Value& val) { \
77
return *val; \
78
} \
79
\
80
inline static bool equal(Value val1, const T& val2) { \
81
return val2 == *val1; \
82
} \
83
\
84
inline static bool equal(const T& val2, Value val1) { \
85
return val2 == *val1; \
86
} \
87
\
88
inline static Value clone(const T& val) { \
89
return new T(val); \
90
} \
91
\
92
inline static void destroy(Value val) { \
93
delete val; \
94
} \
95
inline static Value defaultValue() { \
96
return new T(); \
97
} \
98
};
99
}
100
#else
101
#define DECL_STORED_STRUCT(T) \
102
template <> \
103
struct StoredType<T > { \
104
typedef T *Value; \
105
typedef T& ReturnedValue; \
106
typedef const T& ReturnedConstValue; \
107
\
108
enum {isPointer=1}; \
109
\
110
inline static T& get(const Value& val) { \
111
return *val; \
112
} \
113
\
114
inline static bool equal(Value val1, const T& val2) { \
115
return val2 == *val1; \
116
} \
117
\
118
inline static bool equal(const T& val2, Value val1) { \
119
return val2 == *val1; \
120
} \
121
\
122
inline static Value clone(const T& val) { \
123
return new T(val); \
124
} \
125
\
126
inline static void destroy(Value val) { \
127
delete val; \
128
} \
129
inline static Value defaultValue() { \
130
return new T(); \
131
} \
132
};
133
}
134
#endif
135
#endif
136
#endif
137
///@endcond
library
tulip-core
include
tulip
StoredType.h
Generated on Thu Mar 28 2013 23:02:11 for Tulip by
1.8.2