Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields  

time.DateOperation.h

00001 /*----------------------------------------------------------------------------
00002   SWORD 2000 - Software With Objects for Rapid Development
00003   Copyright (C) 2003 Eric NICOLAS
00004   ----------------------------------------------------------------------------
00005   SWORD is free software; you can redistribute it and/or modify
00006   it under the terms of the GNU Lesser General Public License as published by
00007   the Free Software Foundation; either version 2 of the License, or
00008   (at your option) any later version.
00009 
00010   SWORD is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013   GNU Lesser General Public License for more details.
00014 
00015   You should have received a copy of the GNU Lesser General Public License
00016   along with SWORD; if not, write to the Free Software
00017   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018   --------------------------------------------------------------------------*/
00019 #ifndef _SWORD_TIME_DATEOPERATION_
00020 #define _SWORD_TIME_DATEOPERATION_
00021 
00022 #include "time.HolidayManager.h"
00023 
00024 namespace sword {
00025 
00027 
00056   class SWORDDECL DateOperation {
00057   public:
00058           DateOperation();
00059     DateOperation(const std::string& description);
00060     ~DateOperation();
00061 
00062     // Business Day Conventions
00063 
00064     enum BDC { bdcNone, bdcModf, bdcNext, bdcPrev, bdcInvalid };
00065     // None    - Do nothing
00066     // Invalid - Indicates an invalid date operation
00067     // Modf    - "Modified-Following"
00068     //           If a target day is a holiday, skip to next
00069     //           business day, except if it would change
00070     //           month in which case skip to the previous
00071     //           business day
00072     // Next    - "Next business day"
00073     //           If a target day is a holiday, skip to the
00074     //           next business day
00075     // Prev    - "Previous business day"
00076     //           If a target day is a holiday, skip to the
00077     //           previous business day
00078 
00079     // Get information
00080     std::string toString() const;
00081     bool empty() const;
00082     bool emptyDelay() const;
00083     bool emptyBdc() const;
00084     bool valid() const;
00085 
00086     // Modify the operation
00087     void parse(const std::string& description);
00088     void clear();
00089     void neg();
00090     void invalidates();
00091 
00092     // Get
00093     int  days() const;
00094     bool workDays() const;
00095     int  months() const;
00096           bool monthEndToEnd() const;
00097           int  years() const;
00098           bool yearEndToEnd() const;
00099     BDC  bdc() const;
00100     PHolidayRepository holidays() const;
00101 
00102     // Set
00103     void days(int days);
00104     void workDays(bool workDays);
00105     void months(int months);
00106           void monthEndToEnd(bool endToEnd);
00107           void years(int years);
00108           void yearEndToEnd(bool endToEnd);
00109     void bdc(BDC bdc);
00110     void holidays(const std::string& holidaysName);
00111     void holidays(PHolidayRepository holidays);
00112 
00113     // Using the operation
00114     void   apply(Date& date, int times=1) const;
00115     void   applyDelay(Date& date, int times=1) const;
00116     void   applyBdc(Date& date) const;
00117     double fraction() const;
00118 
00119     // Simple atomic operations
00120     static void addWorkDays(Date& date, int days, const HolidayRepository& holidays);
00121     static void addWorkDayModified(Date& date, const HolidayRepository& holidays);
00122 
00123     // Syntax error in a date operation description
00124     class SyntaxException : public Exception {};
00125 
00126   private:
00127     int  years_;
00128     bool yearEndToEnd_;
00129     int  months_;
00130     bool monthEndToEnd_;
00131     int  days_;
00132     bool workDays_;
00133 
00134     BDC  bdc_;
00135     PHolidayRepository holidays_;
00136   };
00137 
00138 } // namespace sword
00139 
00140 #include "sword.private/time.DateOperation.inl"
00141 
00142 #endif // _SWORD_TIME_DATEOPERATION_

Generated on Tue Dec 23 20:08:56 2003 for SWORD by doxygen1.3-rc2