Changeset 1122


Ignore:
Timestamp:
05/05/17 08:58:36 (4 years ago)
Author:
rlacroix
Message:

CTemporalFilter: Improve const-correctness.

Location:
XIOS/trunk/src/filter
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/filter/temporal_filter.cpp

    r1121 r1122  
    55namespace xios 
    66{ 
     7  static func::CFunctor* createFunctor(const std::string& opId, bool ignoreMissingValue, double missingValue, CArray<double, 1>& tmpData); 
     8 
    79  CTemporalFilter::CTemporalFilter(CGarbageCollector& gc, const std::string& opId, 
    810                                   const CDate& initDate, const CDuration samplingFreq, const CDuration samplingOffset, const CDuration opFreq, 
    911                                   bool ignoreMissingValue /*= false*/, double missingValue /*= 0.0*/) 
    1012    : CFilter(gc, 1, this) 
     13    , functor(createFunctor(opId, ignoreMissingValue, missingValue, tmpData)) 
    1114    , samplingFreq(samplingFreq) 
    1215    , opFreq(opFreq) 
     
    1417    , nextOperationDate(initDate + samplingOffset + opFreq) 
    1518    , isFirstOperation(true) 
     19    , isOnceOperation(functor->timeType() == func::CFunctor::once) 
    1620  { 
    17     double defaultValue = ignoreMissingValue ? std::numeric_limits<double>::quiet_NaN() : missingValue; 
    18      
    19 #define DECLARE_FUNCTOR(MType, mtype) \ 
    20     if (opId.compare(#mtype) == 0) \ 
    21     { \ 
    22       if (ignoreMissingValue) \ 
    23       { \ 
    24         functor.reset(new func::C##MType(tmpData, defaultValue)); \ 
    25       } \ 
    26       else \ 
    27       { \ 
    28         functor.reset(new func::C##MType(tmpData)); \ 
    29       } \ 
    30     } 
    31  
    32 #include "functor_type.conf" 
    33  
    34     if (!functor) 
    35       ERROR("CTemporalFilter::CTemporalFilter(CGarbageCollector& gc, const std::string& opId, ...)", 
    36             << "\"" << opId << "\" is not a valid operation."); 
    37  
    38     isOnceOperation = (functor->timeType() == func::CFunctor::once); 
    3921  } 
    4022 
     
    8062    return isOnceOperation ? isFirstOperation : (date >= nextSamplingDate || date + samplingFreq > nextOperationDate); 
    8163  } 
     64 
     65  static func::CFunctor* createFunctor(const std::string& opId, bool ignoreMissingValue, double missingValue, CArray<double, 1>& tmpData) 
     66  { 
     67    func::CFunctor* functor = NULL; 
     68 
     69    double defaultValue = ignoreMissingValue ? std::numeric_limits<double>::quiet_NaN() : missingValue; 
     70 
     71#define DECLARE_FUNCTOR(MType, mtype) \ 
     72    if (opId.compare(#mtype) == 0) \ 
     73    { \ 
     74      if (ignoreMissingValue) \ 
     75      { \ 
     76        functor = new func::C##MType(tmpData, defaultValue); \ 
     77      } \ 
     78      else \ 
     79      { \ 
     80        functor = new func::C##MType(tmpData); \ 
     81      } \ 
     82    } 
     83 
     84#include "functor_type.conf" 
     85 
     86    if (!functor) 
     87      ERROR("createFunctor(const std::string& opId, ...)", 
     88            << "\"" << opId << "\" is not a valid operation."); 
     89 
     90    return functor; 
     91  } 
    8292} // namespace xios 
  • XIOS/trunk/src/filter/temporal_filter.hpp

    r1119 r1122  
    4848 
    4949    private: 
    50       boost::scoped_ptr<func::CFunctor> functor; //!< The functor corresponding to the temporal operation 
     50      const boost::scoped_ptr<func::CFunctor> functor; //!< The functor corresponding to the temporal operation 
    5151      CArray<double, 1> tmpData; //!< The array of data used for temporary storage 
    5252      const CDuration samplingFreq; //!< The sampling frequency, i.e. the frequency at which the input data will be used 
     
    5555      CDate nextOperationDate; //!< The date of the next operation 
    5656      bool isFirstOperation; //!< True before the first operation was been computed 
    57       bool isOnceOperation; //!< True if the operation should be computed just once 
     57      const bool isOnceOperation; //!< True if the operation should be computed just once 
    5858  }; // class CTemporalFilter 
    5959} // namespace xios 
Note: See TracChangeset for help on using the changeset viewer.