File indexing completed on 2025-02-21 09:58:05
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef DDCOND_CONDITIONSSELECTORS_H
0014 #define DDCOND_CONDITIONSSELECTORS_H
0015
0016
0017 #include "DD4hep/Conditions.h"
0018 #include "DD4hep/detail/ConditionsInterna.h"
0019
0020
0021 namespace dd4hep {
0022
0023
0024 namespace cond {
0025
0026
0027 namespace Operators {
0028
0029
0030
0031
0032
0033
0034
0035 class Cond__Oper {
0036 public:
0037 typedef Condition cond_t;
0038 typedef Condition::Object object_t;
0039 typedef std::pair<const Condition::key_type,Condition> mapentry_t;
0040 typedef std::pair<const Condition::key_type,object_t*> ptr_mapentry_t;
0041 };
0042
0043
0044
0045
0046
0047
0048
0049 template <typename T> struct SequenceSelect : public Cond__Oper {
0050 T& mapping;
0051 SequenceSelect(T& o) : mapping(o) { }
0052 bool operator()(Condition::Object* o) const
0053 { mapping.emplace(mapping.end(), o); return true; }
0054 };
0055
0056
0057
0058
0059
0060
0061
0062 template <typename T> struct MapSelect : public Cond__Oper {
0063 T& mapping;
0064 MapSelect(T& o) : mapping(o) { }
0065 bool operator()(Condition::Object* o) const
0066 { return mapping.emplace(o->hash,o).second; }
0067 };
0068
0069
0070
0071
0072
0073
0074
0075 template <typename T> struct MapConditionsSelect : public ConditionsSelect {
0076 T& mapping;
0077 MapConditionsSelect(T& o) : mapping(o) { }
0078 virtual bool operator()(Condition::Object* o) const
0079 { return mapping.emplace(o->hash,o).second; }
0080 virtual size_t size() const { return mapping.size(); }
0081 };
0082
0083
0084
0085
0086
0087
0088
0089 template <typename T> struct PoolSelect : public Cond__Oper {
0090 T& pool;
0091 PoolSelect(T& o) : pool(o) { }
0092 bool operator()(Condition::Object* o) const { return pool.insert(o); }
0093 };
0094
0095
0096
0097
0098
0099
0100
0101 template <typename T> struct PoolRemove : public Cond__Oper {
0102 T& pool;
0103 PoolRemove(T& o) : pool(o) { }
0104 bool operator()(object_t* o) const { pool.onRemove(o); delete(o); return true; }
0105 };
0106
0107
0108
0109
0110
0111
0112
0113 template <typename T> struct ActiveSelect : public Cond__Oper {
0114 public:
0115 T& collection;
0116 ActiveSelect(T& p) : collection(p) {}
0117 bool operator()(object_t* o) const {
0118 if ( (o->flags & Condition::ACTIVE) ) {
0119 collection.emplace(collection.end(),o);
0120 return true;
0121 }
0122 return false;
0123 }
0124 };
0125
0126
0127
0128
0129
0130
0131
0132 template<typename collection_type> class KeyedSelect : public Cond__Oper {
0133 cond_t::key_type key;
0134 collection_type& collection;
0135 public:
0136 KeyedSelect(cond_t::key_type k, collection_type& p) : key(k), collection(p) { }
0137 bool operator()(object_t* o) const {
0138 if ( o->hash == key ) {
0139 collection.emplace(collection.end(),o);
0140 return true;
0141 }
0142 return false;
0143 }
0144 };
0145
0146
0147
0148
0149
0150
0151
0152 class KeyFind : public Cond__Oper {
0153 cond_t::key_type hash;
0154 public:
0155 KeyFind(cond_t::key_type h) : hash(h) { }
0156 bool operator()(const object_t* o) const { return o->hash == hash; }
0157 };
0158
0159
0160
0161
0162
0163
0164
0165 template <typename OPER> class OperatorWrapper : public Cond__Oper {
0166 public:
0167 typedef OPER operator_t;
0168 typedef OperatorWrapper<operator_t> wrapper_t;
0169 operator_t& oper;
0170 public:
0171 OperatorWrapper(operator_t& o) : oper(o) { }
0172 bool operator()(object_t* o) const { return oper(o); }
0173 bool operator()(const cond_t& o) const { return oper(o.ptr()); }
0174 bool operator()(const mapentry_t& o) const { return oper(o.second.ptr()); }
0175 bool operator()(const ptr_mapentry_t& o) const { return oper(o.second); }
0176 };
0177
0178
0179
0180
0181
0182
0183
0184 template <typename OPER> class ConditionsOperation : public Cond__Oper {
0185 public:
0186 typedef OPER operator_t;
0187 typedef ConditionsOperation<operator_t> wrapper_t;
0188 operator_t oper;
0189 public:
0190 ConditionsOperation(const operator_t& o) : oper(o) { }
0191 bool operator()(object_t* o) const { return oper(o); }
0192 bool operator()(const cond_t& o) const { return oper(o.ptr()); }
0193 bool operator()(const mapentry_t& o) const { return oper(o.second.ptr()); }
0194 bool operator()(const ptr_mapentry_t& o) const { return oper(o.second); }
0195 };
0196
0197
0198
0199
0200
0201
0202
0203 template <typename oper_type> OperatorWrapper<oper_type> operatorWrapper(oper_type& oper) {
0204 return OperatorWrapper<oper_type>(oper);
0205 }
0206
0207
0208
0209
0210
0211
0212
0213 template <typename P> inline ConditionsOperation<PoolRemove<P> > poolRemove(P& pool)
0214 { return ConditionsOperation<PoolRemove<P> >(PoolRemove<P>(pool)); }
0215
0216
0217
0218
0219
0220
0221
0222 template <typename P> inline ConditionsOperation<PoolSelect<P> > poolSelect(P& pool)
0223 { return ConditionsOperation<PoolSelect<P> >(PoolSelect<P>(pool)); }
0224
0225
0226
0227
0228
0229
0230
0231 template <typename T> inline MapConditionsSelect<T> mapConditionsSelect(T& collection)
0232 { return MapConditionsSelect<T>(collection); }
0233
0234
0235
0236
0237
0238
0239
0240 template <typename C> inline
0241 ConditionsOperation<SequenceSelect<C> > sequenceSelect(C& coll) {
0242 typedef SequenceSelect<C> operator_t;
0243 return ConditionsOperation<operator_t>(operator_t(coll));
0244 }
0245
0246
0247
0248
0249
0250
0251
0252 template <typename C> inline
0253 ConditionsOperation<SequenceSelect<C> > mapSelect(C& coll) {
0254 typedef MapSelect<C> operator_t;
0255 return ConditionsOperation<operator_t>(operator_t(coll));
0256 }
0257
0258
0259
0260
0261
0262
0263
0264 template <typename C> inline ConditionsOperation<ActiveSelect<C> > activeSelect(C& coll)
0265 { return ConditionsOperation<ActiveSelect<C> >(ActiveSelect<C>(coll)); }
0266
0267
0268
0269
0270
0271
0272
0273 template <typename C> inline
0274 ConditionsOperation<KeyedSelect<C> > keyedSelect(Condition::key_type key, C& coll)
0275 { return ConditionsOperation<KeyedSelect<C> >(KeyedSelect<C>(key, coll)); }
0276
0277
0278
0279
0280
0281
0282
0283 ConditionsOperation<KeyFind> inline keyFind(Condition::key_type key)
0284 { return ConditionsOperation<KeyFind>(KeyFind(key)); }
0285
0286 }
0287 }
0288 }
0289 #endif