Changeset 2731


Ignore:
Timestamp:
01/16/13 16:45:43 (11 years ago)
Author:
Takeshi Nakazato
Message:

New Development: No

JIRA Issue: Yes CAS-4770

Ready for Test: Yes

Interface Changes: Yes/No?

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: Yes/No?

Module(s): Module Names change impacts.

Description: Describe your changes here...

Redefined Locator and its derived classes as template class.


Location:
trunk/src
Files:
4 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/BisectionLocator.h

    r2730 r2731  
    2121 * @author TakeshiNakazato
    2222 */
    23 class BisectionLocator : public Locator {
     23template <class T> class BisectionLocator : public Locator<T> {
    2424public:
    2525  // Default constructor.
     
    3131  // @param[in] copystorage whether allocate internal memory or not.
    3232  // @see Locator::set()
    33   BisectionLocator(double *v, unsigned int n, bool copystorage=true);
     33  BisectionLocator(T *v, unsigned int n, bool copystorage=true);
    3434
    3535  // Destructor.
     
    4040  // @return location as an index j.
    4141  // @see Locator::locate()
    42   unsigned int locate(double x);
     42  unsigned int locate(T x);
    4343};
    4444
    4545}
     46
     47#include "BisectionLocator.tcc"
     48
    4649#endif
  • trunk/src/BufferedBisectionLocator.h

    r2730 r2731  
    2222 * @author TakeshiNakazato
    2323 */
    24 class BufferedBisectionLocator : public Locator {
     24template <class T> class BufferedBisectionLocator : public Locator<T> {
    2525public:
    2626  // Default constructor.
     
    3232  // @param[in] copystorage whether allocate internal memory or not.
    3333  // @see Locator::set()
    34   BufferedBisectionLocator(double *v, unsigned int n, bool copystorage=true);
     34  BufferedBisectionLocator(T *v, unsigned int n, bool copystorage=true);
    3535
    3636  // Destructor.
     
    4141  // @return location as an index j.
    4242  // @see Locator::locate()
    43   unsigned int locate(double x);
     43  unsigned int locate(T x);
    4444private:
    4545
     
    4949
    5050}
     51
     52#include "BufferedBisectionLocator.tcc"
     53
    5154#endif
  • trunk/src/CMakeLists.txt

    r2729 r2731  
    8080     ${SRCDIR}/Calibrator.cpp
    8181     ${SRCDIR}/PSAlmaCalibrator.cpp
    82      ${SRCDIR}/Locator.cpp
    83      ${SRCDIR}/BisectionLocator.cpp
    84      ${SRCDIR}/HuntLocator.cpp
    85      ${SRCDIR}/BufferedBisectionLocator.cpp
    8682     ${SRCDIR}/Interpolator1D.cpp
    8783     ${SRCDIR}/NearestInterpolator1D.cpp
  • trunk/src/HuntLocator.h

    r2730 r2731  
    2121 * @author TakeshiNakazato
    2222 */
    23 class HuntLocator : public Locator {
     23template <class T> class HuntLocator : public Locator<T> {
    2424public:
    2525  // Default constructor.
     
    3131  // @param[in] copystorage whether allocate internal memory or not.
    3232  // @see Locator::set()
    33   HuntLocator(double *v, unsigned int n, bool copystorage=true);
     33  HuntLocator(T *v, unsigned int n, bool copystorage=true);
    3434
    3535  // Destructor.
     
    4141  // @return location as an index j.
    4242  // @see Locator::locate()
    43   unsigned int locate(double x);
     43  unsigned int locate(T x);
    4444private:
     45  // Hunt algorithm
     46  // @param[in] x input value to be located.
     47  // @param[in,out] left input: the starting point for hunt.
     48  //                     output: the left index of hunted region.
     49  // @param[out] right the right index of hunted region.
     50  void hunt(T x, unsigned int &left, unsigned int &right);
     51
    4552  // Storage for previous result.
    4653  unsigned int prev_;
     
    4855
    4956}
     57
     58#include "HuntLocator.tcc"
     59
    5060#endif
  • trunk/src/Interpolator1D.cpp

    r2730 r2731  
    1616
    1717#include "Interpolator1D.h"
     18#include "Locator.h"
    1819#include "BisectionLocator.h"
    1920#include "HuntLocator.h"
     
    8889  if (!locator_) {
    8990    if (n_ > 1000)
    90       locator_ = new HuntLocator();
     91      locator_ = new HuntLocator<double>();
    9192    else
    92       locator_ = new BisectionLocator();
     93      locator_ = new BisectionLocator<double>();
    9394  }
    9495}
  • trunk/src/Interpolator1D.h

    r2730 r2731  
    8787
    8888  // Pointer to the Locator object.
    89   Locator *locator_;
     89  Locator<double> *locator_;
    9090};
    9191
  • trunk/src/Locator.h

    r2730 r2731  
    1919 * @author TakeshiNakazato
    2020 */
    21 class Locator {
     21template <class T> class Locator {
    2222public:
    2323  // Default constructor.
     
    2929  // @param[in] copystorage whether allocate internal memory or not.
    3030  // @see set()
    31   Locator(double *v, unsigned int n, bool copystorage=true);
    32 
     31  Locator(T *v, unsigned int n, bool copystorage=true);
     32 
    3333  // Set data. The data must be sorted in either ascending or descending
    3434  // order, and must not have any duplicate elements.
     
    4242  // it will take a risk to allow to edit the data to be searched from
    4343  // outside the class.
    44   void set(double *v, unsigned int n, bool copystorage=true);
    45 
     44  void set(T *v, unsigned int n, bool copystorage=true);
     45 
    4646  // Destructor.
    4747  virtual ~Locator();
    48 
     48 
    4949  // Return right hand side index of location.
    5050  // @param[in] x input value to be located.
     
    5454  // case while x_[j-1] > x >= x_[j] for descending case.
    5555  // Returned value 0 or x.nelements() indicates out of range.
    56   virtual unsigned int locate(double x) = 0;
    57 
     56  virtual unsigned int locate(T x) = 0;
     57 
    5858protected:
    5959  // Bisection search.
     
    6161  // @param[in] left the leftmost index to search.
    6262  // @param[in] right the rightmost index to search.
    63   unsigned int bisection(double x, unsigned int left, unsigned int right);
     63  unsigned int bisection(T x, unsigned int left, unsigned int right);
    6464 
    65   // Hunt algorithm
    66   // @param[in] x input value to be located.
    67   // @param[in,out] left input: the starting point for hunt.
    68   //                     output: the left index of hunted region.
    69   // @param[out] right the right index of hunted region.
    70   void hunt(double x, unsigned int &left, unsigned int &right);
    71 
    7265  // Pointer to the data.
    73   double *x_;
     66  T *x_;
    7467
    7568  // Length of the data.
     
    8477
    8578}
     79
     80#include "Locator.tcc"
     81
    8682#endif
Note: See TracChangeset for help on using the changeset viewer.