00001
00013 #ifndef __VECTORITERATOR_H
00014 #define __VECTORITERATOR_H
00015
00016 #include "jbltools/sfh/FloatFun.h"
00017 #include "jbltools/sfh/FillIterator.h"
00018
00019 #include <vector>
00020
00021 #if (DEBUG>0)
00022 #include <iostream>
00023 #endif
00024
00026
00028 template <class Row, class Member=float>
00029 class VectorFloatFun: public FloatFun {
00030 public:
00032 VectorFloatFun (const std::vector<Row>& theVector_,
00033 Member Row::* p_mem_,
00034 const FillIterator& iter_,
00035 const char* name_ = "?"
00036 )
00037 : FloatFun (std::string(name_ ? name_ : "?")+'['+iter_.getName()+']'),
00038 theVector (theVector_),
00039 p_mem (p_mem_),
00040 iter (iter_)
00041 {
00042 assert (&theVector);
00043 assert (&iter);
00044 #if (DEBUG>0)
00045 std::cout << "VectorFloatFun: created '" << getName() << "'\n";
00046 #endif
00047 }
00048
00050 Float_FF operator() () const
00051 { return theVector[iter()].*p_mem; }
00052
00054 virtual const FillIterator *getIterator() const { return &iter; }
00055
00056 protected:
00058 virtual ~VectorFloatFun() {}
00059
00060
00061 const std::vector<Row>& theVector;
00062 Member Row::* p_mem;
00063
00070 const FillIterator& iter;
00071 };
00072
00074
00076 template <class Row, class Member=float>
00077 class VectorFloatFunFun: public FloatFun {
00078 public:
00080 VectorFloatFunFun (const std::vector<Row>& theVector_,
00081 Member (Row::* p_mem_)() const,
00082 const FillIterator& iter_,
00083 const char* name_ = "?"
00084 )
00085 : FloatFun (std::string(name_ ? name_ : "?")+'['+iter_.getName()+']'),
00086 theVector (theVector_),
00087 p_mem (p_mem_),
00088 iter (iter_)
00089 {
00090 assert (&theVector);
00091 assert (&iter);
00092 #if (DEBUG>0)
00093 std::cout << "VectorFloatFunFun: created '" << getName() << "'\n";
00094 #endif
00095 }
00096
00098 Float_FF operator() () const
00099 { return (theVector[iter()].*p_mem)(); }
00100
00102 virtual const FillIterator *getIterator() const { return &iter; }
00103
00104 protected:
00106 virtual ~VectorFloatFunFun() {}
00107
00108
00109 const std::vector<Row>& theVector;
00110 Member (Row::* p_mem)() const;
00111
00118 const FillIterator& iter;
00119 };
00120
00122
00124 template <class Row, class Member=float, class Arg=float>
00125 class VectorFloatFunFunArg: public FloatFun {
00126 public:
00128 VectorFloatFunFunArg (const std::vector<Row>& theVector_,
00129 Member (Row::* p_mem_)(Arg) const,
00130 Arg arg_,
00131 const FillIterator& iter_,
00132 const char* name_ = "?"
00133 )
00134 : FloatFun (std::string(name_ ? name_ : "?")+'['+iter_.getName()+']'),
00135 theVector (theVector_),
00136 p_mem (p_mem_),
00137 arg(arg_),
00138 iter (iter_)
00139 {
00140 assert (&theVector);
00141 assert (&iter);
00142 #if (DEBUG>0)
00143 std::cout << "VectorFloatFunFunArg: created '" << getName() << "'\n";
00144 #endif
00145 }
00146
00148 Float_FF operator() () const
00149 { return (theVector[iter()].*p_mem)(arg); }
00150
00152 virtual const FillIterator *getIterator() const { return &iter; }
00153
00154 protected:
00156 virtual ~VectorFloatFunFunArg() {}
00157
00158
00159 const std::vector<Row>& theVector;
00160 Member (Row::* p_mem)(Arg) const;
00161 Arg arg;
00162
00169 const FillIterator& iter;
00170 };
00171
00173
00175 template <class Row, class Member=int>
00176 class VectorIntFun: public IntFun {
00177 public:
00179 VectorIntFun (const std::vector<Row>& theVector_,
00180 Member Row::* p_mem_,
00181 const FillIterator& iter_,
00182 const char* name_ = "?"
00183 )
00184 : IntFun (std::string(name_ ? name_ : "?")+'['+iter_.getName()+']'),
00185 theVector (theVector_),
00186 p_mem (p_mem_),
00187 iter (iter_)
00188 {
00189 assert (&theVector);
00190 assert (&iter);
00191 #if (DEBUG>0)
00192 std::cout << "VectorIntFun: created '" << getName() << "'\n";
00193 #endif
00194 }
00195
00197 int operator() () const
00198 { return theVector[iter()].*p_mem; }
00199
00201 virtual const FillIterator *getIterator() const { return &iter; }
00202
00203 protected:
00205 virtual ~VectorIntFun() {}
00206
00207
00208 const std::vector<Row>& theVector;
00209 Member Row::* p_mem;
00210
00217 const FillIterator& iter;
00218 };
00219
00221
00223 template <class Row, class Member=int>
00224 class VectorIntFunFun: public IntFun {
00225 public:
00227 VectorIntFunFun (const std::vector<Row>& theVector_,
00228 Member (Row::* p_mem_)() const,
00229 const FillIterator& iter_,
00230 const char* name_ = "?"
00231 )
00232 : IntFun (std::string(name_ ? name_ : "?")+'['+iter_.getName()+']'),
00233 theVector (theVector_),
00234 p_mem (p_mem_),
00235 iter (iter_)
00236 {
00237 assert (&theVector);
00238 assert (&iter);
00239 #if (DEBUG>0)
00240 std::cout << "VectorFloatFunFun: created '" << getName() << "'\n";
00241 #endif
00242 }
00243
00245 int operator() () const
00246 { return (theVector[iter()].*p_mem)(); }
00247
00249 virtual const FillIterator *getIterator() const { return &iter; }
00250
00251 protected:
00253 virtual ~VectorIntFunFun() {}
00254
00255
00256 const std::vector<Row>& theVector;
00257 Member (Row::* p_mem)() const;
00258
00265 const FillIterator& iter;
00266 };
00267
00269
00271 template <class Row, class Member=int, class Arg=int>
00272 class VectorIntFunFunArg: public IntFun {
00273 public:
00275 VectorIntFunFunArg (const std::vector<Row>& theVector_,
00276 Member (Row::* p_mem_)(Arg) const,
00277 Arg arg_,
00278 const FillIterator& iter_,
00279 const char* name_ = "?"
00280 )
00281 : IntFun (std::string(name_ ? name_ : "?")+'['+iter_.getName()+']'),
00282 theVector (theVector_),
00283 p_mem (p_mem_),
00284 arg(arg_),
00285 iter (iter_)
00286 {
00287 assert (&theVector);
00288 assert (&iter);
00289 #if (DEBUG>0)
00290 std::cout << "VectorIntFunFunArg: created '" << getName() << "'\n";
00291 #endif
00292 }
00293
00295 int operator() () const
00296 { return (theVector[iter()].*p_mem)(arg); }
00297
00299 virtual const FillIterator *getIterator() const { return &iter; }
00300
00301 protected:
00303 virtual ~VectorIntFunFunArg() {}
00304
00305
00306 const std::vector<Row>& theVector;
00307 Member (Row::* p_mem)(Arg) const;
00308 Arg arg;
00309
00316 const FillIterator& iter;
00317 };
00318
00320
00322 template <class Row, class Member=bool>
00323 class VectorBaseCut: public BaseCut {
00324 public:
00326 VectorBaseCut (const std::vector<Row>& theVector_,
00327 Member Row::* p_mem_,
00328 const FillIterator& iter_,
00329 const char* name_ = "?"
00330 )
00331 : BaseCut (std::string(name_ ? name_ : "?")+'['+iter_.getName()+']'),
00332 theVector (theVector_),
00333 p_mem (p_mem_),
00334 iter (iter_)
00335 {
00336 assert (&theVector);
00337 assert (&iter);
00338 #if (DEBUG>0)
00339 std::cout << "VectorBaseCut: created '" << getName() << "'\n";
00340 #endif
00341 }
00342
00344 bool operator() () const
00345 { return theVector[iter()].*p_mem; }
00346
00348 virtual const FillIterator *getIterator() const { return &iter; }
00349
00350 protected:
00352 virtual ~VectorBaseCut() {}
00353
00354
00355 const std::vector<Row>& theVector;
00356 Member Row::* p_mem;
00357
00364 const FillIterator& iter;
00365 };
00366
00368
00370 template <class Row, class Member=float>
00371 class VectorBaseCutFun: public BaseCut {
00372 public:
00374 VectorBaseCutFun (const std::vector<Row>& theVector_,
00375 Member (Row::* p_mem_)() const,
00376 const FillIterator& iter_,
00377 const char* name_ = "?"
00378 )
00379 : BaseCut (std::string(name_ ? name_ : "?")+'['+iter_.getName()+']'),
00380 theVector (theVector_),
00381 p_mem (p_mem_),
00382 iter (iter_)
00383 {
00384 assert (&theVector);
00385 assert (&iter);
00386 #if (DEBUG>0)
00387 std::cout << "VectorBaseCutFun: created '" << getName() << "'\n";
00388 #endif
00389 }
00390
00392 bool operator() () const
00393 { return (theVector[iter()].*p_mem)(); }
00394
00396 virtual const FillIterator *getIterator() const { return &iter; }
00397
00398 protected:
00400 virtual ~VectorBaseCutFun() {}
00401
00402
00403 const std::vector<Row>& theVector;
00404 Member (Row::* p_mem)() const;
00405
00412 const FillIterator& iter;
00413 };
00414
00416
00418 template <class Row, class Member=float, class Arg=bool>
00419 class VectorBaseCutFunArg: public BaseCut {
00420 public:
00422 VectorBaseCutFunArg (const std::vector<Row>& theVector_,
00423 Member (Row::* p_mem_)(Arg) const,
00424 Arg arg_,
00425 const FillIterator& iter_,
00426 const char* name_ = "?"
00427 )
00428 : BaseCut (std::string(name_ ? name_ : "?")+'['+iter_.getName()+']'),
00429 theVector (theVector_),
00430 p_mem (p_mem_),
00431 arg(arg_),
00432 iter (iter_)
00433 {
00434 assert (&theVector);
00435 assert (&iter);
00436 #if (DEBUG>0)
00437 std::cout << "VectorBaseCutFunArg: created '" << getName() << "'\n";
00438 #endif
00439 }
00440
00442 bool operator() () const
00443 { return (theVector[iter()].*p_mem)(arg); }
00444
00446 virtual const FillIterator *getIterator() const { return &iter; }
00447
00448 protected:
00450 virtual ~VectorBaseCutFunArg() {}
00451
00452
00453 const std::vector<Row>& theVector;
00454 Member (Row::* p_mem)(Arg) const;
00455 Arg arg;
00456
00463 const FillIterator& iter;
00464 };
00465
00466
00468
00532 template <class Row>
00533 class VectorIterator: public FillIterator {
00534 public:
00536 explicit VectorIterator (const std::vector<Row>& theVector_,
00537 const char* name_ = "?"
00538 )
00539 : FillIterator (std::string(name_ ? name_ : "?")),
00540 theVector(theVector_),
00541 index (0)
00542 {
00543 assert (&theVector);
00544 #if (DEBUG>0)
00545 std::cout << "VectorIterator: created '" << getName() << "'\n";
00546 #endif
00547 }
00548
00550 virtual int operator() () const {
00551 return index;
00552 }
00553
00555 virtual bool next() {
00556 return (++index < theVector.size());
00557 }
00558
00560 virtual bool reset() {
00561 return ((index = 0) < theVector.size());
00562 }
00563
00565 virtual bool isValid() const {
00566 return (index >= 0) && (index < theVector.size());
00567 }
00568
00570
00574 template <class Member>
00575 VectorFloatFun<Row, Member>& Float(Member Row::* p_mem,
00576 const char *name_ = "?"
00577 ) const {
00578 return *new VectorFloatFun<Row, Member> (theVector, p_mem, *this, name_);
00579 }
00580
00582
00589 template <class Member>
00590 VectorFloatFunFun<Row, Member>& Float(Member (Row::* p_mem)() const,
00591 const char *name_ = "?"
00592 ) const {
00593 return *new VectorFloatFunFun<Row, Member> (theVector, p_mem, *this, name_);
00594 }
00595
00597
00605 template <class Member, class Arg>
00606 VectorFloatFunFunArg<Row, Member, Arg>& Float(Member (Row::* p_mem)(Arg) const,
00607 Arg arg_,
00608 const char *name_ = "?"
00609 ) const {
00610 return *new VectorFloatFunFunArg<Row, Member, Arg> (theVector, p_mem, arg_, *this, name_);
00611 }
00612
00614
00618 template <class Member>
00619 VectorIntFun<Row, Member>& Int(Member Row::* p_mem,
00620 const char *name_ = "?"
00621 ) const {
00622 return *new VectorIntFun<Row, Member> (theVector, p_mem, *this, name_);
00623 }
00624
00626
00633 template <class Member>
00634 VectorIntFunFun<Row, Member>& Int(Member (Row::* p_mem)() const,
00635 const char *name_ = "?"
00636 ) const {
00637 return *new VectorIntFunFun<Row, Member> (theVector, p_mem, *this, name_);
00638 }
00639
00641
00649 template <class Member, class Arg>
00650 VectorIntFunFunArg<Row, Member, Arg>& Int(Member (Row::* p_mem)(Arg) const,
00651 Arg arg_,
00652 const char *name_ = "?"
00653 ) const {
00654 return *new VectorIntFunFunArg<Row, Member, Arg> (theVector, p_mem, arg_, *this, name_);
00655 }
00656
00658
00662 template <class Member>
00663 VectorBaseCut<Row, Member>& Bool(Member Row::* p_mem,
00664 const char *name_ = "?"
00665 ) const {
00666 return *new VectorBaseCut<Row, Member> (theVector, p_mem, *this, name_);
00667 }
00668
00670
00677 template <class Member>
00678 VectorBaseCutFun<Row, Member>& Bool(Member (Row::* p_mem)() const,
00679 const char *name_ = "?"
00680 ) const {
00681 return *new VectorBaseCutFun<Row, Member> (theVector, p_mem, *this, name_);
00682 }
00684
00692 template <class Member, class Arg>
00693 VectorBaseCutFunArg<Row, Member, Arg>& Bool(Member (Row::* p_mem)(Arg) const,
00694 Arg arg_,
00695 const char *name_ = "?"
00696 ) const {
00697 return *new VectorBaseCutFunArg<Row, Member, Arg> (theVector, p_mem, arg_, *this, name_);
00698 }
00699
00700 protected:
00702 virtual ~VectorIterator() {}
00703
00704
00705 const std::vector<Row>& theVector;
00706 unsigned int index;
00707 };
00708
00709 #endif