uLib-0.2
Main Page
Namespaces
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Object.h
Go to the documentation of this file.
1
/*//////////////////////////////////////////////////////////////////////////////
2
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
4
5
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
6
All rights reserved
7
8
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
9
10
------------------------------------------------------------------
11
This library is free software; you can redistribute it and/or
12
modify it under the terms of the GNU Lesser General Public
13
License as published by the Free Software Foundation; either
14
version 3.0 of the License, or (at your option) any later version.
15
16
This library is distributed in the hope that it will be useful,
17
but WITHOUT ANY WARRANTY; without even the implied warranty of
18
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19
Lesser General Public License for more details.
20
21
You should have received a copy of the GNU Lesser General Public
22
License along with this library.
23
25
26
27
28
#ifndef U_CORE_OBJECT_H
29
#define U_CORE_OBJECT_H
30
31
#include <iostream>
32
33
// WARNING: COPILE ERROR if this goes after mpl/vector //
34
//#include "Core/Vector.h"
35
36
#include "Core/Types.h"
37
#include "Core/Debug.h"
38
39
#include "Core/Function.h"
40
#include "Core/Signal.h"
41
42
#include "Core/Mpl.h"
43
#include "Core/Serializable.h"
44
#include "Core/ObjectProps.h"
45
#include "Core/Uuid.h"
46
47
namespace boost {
48
namespace archive {
49
class polymorphic_iarchive;
50
class polymorphic_oarchive;
51
} // archive
52
} // boost
53
54
55
namespace uLib {
56
57
58
class Version {
59
public:
60
static const char *PackageName;
61
static const char *VersionNumber;
62
static const char *Release;
63
};
64
65
66
67
68
69
73
74
75
79
class Object : public ObjectPropable
80
{
81
82
83
public:
84
// std::string name;
85
// void PrintName() { std::cout << "Ob name: " << name << "\n"; }
86
87
Object();
88
Object(const Object ©);
89
~Object();
90
92
// PARAMETERS //
93
94
// FIXX !!!
95
virtual void DeepCopy(const Object ©);
96
97
99
// SERIALIZATION //
100
101
template <class ArchiveT> void serialize(ArchiveT &ar, const unsigned int version) {
102
ObjectPropable::serialize(ar,version);
103
}
104
template <class ArchiveT> void save_override(ArchiveT &ar,const unsigned int version) {}
105
106
void SaveConfig(std::ostream &os, int version = 0);
107
void LoadConfig(std::istream &is, int version = 0);
108
109
static void SaveXml(std::ostream &os, Object &ob);
110
static void LoadXml(std::istream &is, Object &ob);
111
112
113
115
// SIGNALS //
116
117
// Qt4 style connector //
118
static bool connect(const Object *ob1, const char *signal_name, const Object *receiver, const char *slot_name) {
119
// // NOT WORKING YET //
120
// 1) find slot pointer from name
121
// SignalBase *sig = ob1->findSignal(signal_name);
122
// GenericMFPtr *slo = receiver->findSlot(slot_name);
123
// if(sig && slo)
124
// return Object::connect(sig,slo->operator ()(),receiver);
125
// else return false;
126
}
127
128
// Qt5 style connector //
129
template <typename Func1, typename Func2>
130
static bool connect( typename FunctionPointer<Func1>::Object *sender, Func1 sigf,
131
typename FunctionPointer<Func2>::Object *receiver, Func2 slof)
132
{
133
SignalBase *sigb = sender->findOrAddSignal(sigf);
134
typedef boost::signals2::signal<typename FunctionPointer<Func2>::SignalSignature> SigT;
135
ConnectSignal(sigb,slof,receiver);
136
}
137
138
template <typename FuncT>
139
static inline bool connect(SignalBase *sigb, FuncT slof, Object *receiver) {
140
ConnectSignal(sigb,slof,receiver);
141
}
142
143
144
template< typename FuncT >
145
inline typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type *
146
addSignal(FuncT fun, const char *name) {
147
typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT;
148
SignalBase *sig = NewSignal(fun);
149
addSignalImpl(sig,fun,name);
150
return (SigT *)sig;
151
}
152
153
template< typename FuncT>
154
inline bool addSlot(FuncT fun, const char *name) {
155
this->addSlotImpl(GenericMFPtr(fun),name);
156
}
157
158
template < typename FuncT >
159
inline typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type *
160
findSignal(FuncT fptr)
161
{
162
typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT;
163
return (SigT *)findSignalImpl(GenericMFPtr(fptr));
164
}
165
166
template < typename FuncT >
167
inline typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type *
168
findOrAddSignal(FuncT fptr)
169
{
170
typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT;
171
SignalBase *sig = findSignalImpl(GenericMFPtr(fptr));
172
if(!sig) {
173
sig = NewSignal(fptr);
174
addSignalImpl(sig,fptr,"signal_name_to_be_implemented");
175
}
176
return (SigT *)sig;
177
}
178
179
180
inline SignalBase *
181
findSignal(const char *name) const
182
{
183
return findSignalImpl(name);
184
}
185
186
inline GenericMFPtr *
187
findSlot(const char *name) const
188
{
189
return findSlotImpl(name);
190
}
191
192
193
void PrintSelf(std::ostream &o) const;
194
195
inline const Object& operator = (const Object ©)
196
{ this->DeepCopy(copy); return *this; }
197
198
199
private:
200
bool addSignalImpl(SignalBase *sig, GenericMFPtr fptr, const char *name);
201
bool addSlotImpl(GenericMFPtr fptr, const char *name);
202
SignalBase *findSignalImpl(const GenericMFPtr &fptr) const;
203
SignalBase *findSignalImpl(const char *name) const;
204
GenericMFPtr *findSlotImpl(const char *name) const;
205
206
friend class boost::serialization::access;
207
friend class ObjectPrivate;
208
class ObjectPrivate *d;
209
};
210
211
212
213
} // uLib
214
216
217
//std::ostream & operator << (std::ostream &os, uLib::Object &ob);
218
//std::ostream & operator << (std::ostream &os, uLib::Object *ob);
219
//std::istream & operator >> (std::istream &is, uLib::Object &ob);
220
221
222
#endif // U_OBJECT_H
Core
Object.h
Generated by
1.8.5