00 //============================================================================ 01 // Name : timeseries_pimpl.h 02 // Author : Simonas Saltenis 03 // Version : 04 // Description : Demos PIMPL 05 //============================================================================ 06 07 #ifndef TIMESERIES_H_INCLUDED 08 #define TIMESERIES_H_INCLUDED 09 10 #include <memory> 11 12 // Note: very few includes! 13 14 namespace TimeData 15 { 16 17 class TimeSeries 18 { // Note: no inline definitions of the methods in the header, just declarations! 19 public: 20 TimeSeries(); 21 22 TimeSeries(const TimeSeries& ts); 23 TimeSeries& operator=(const TimeSeries& ts); 24 25 TimeSeries(TimeSeries&& ts) noexcept; 26 TimeSeries& operator=(TimeSeries&& tsh) noexcept; 27 28 // Important to forward-declare 29 // Otherwise, if this is missing, the default inline destructor will be generated, which will call std::unique_ptr destructor, 30 // which will do delete of the raw pointer to TimeSeriesImpl at which point the compilation will fail, 31 // as TimeSeriesImpl is not a complete type in this compilation unit. 32 ~TimeSeries(); 33 34 TimeSeries& addValue (int v); 35 36 unsigned amplitude () const; 37 38 bool operator<(const TimeSeries& t) const; 39 40 TimeSeries& operator+=(const TimeSeries& t); 41 TimeSeries operator+ (const TimeSeries& t) const; 42 43 private: 44 class TimeSeriesImpl; // Just a declaration 45 46 std::unique_ptr<TimeSeriesImpl> pimpl; 47 }; 48 49 } // namespace TimeData 50 51 #endif // TIMESERIES_H_INCLUDED 52