coherence/io/pof/RawDate.hpp

00001 /*
00002 * RawDate.hpp
00003 *
00004 * Copyright (c) 2000, 2009, Oracle and/or its affiliates. All rights reserved.
00005 *
00006 * Oracle is a registered trademarks of Oracle Corporation and/or its
00007 * affiliates.
00008 *
00009 * This software is the confidential and proprietary information of Oracle
00010 * Corporation. You shall not disclose such confidential and proprietary
00011 * information and shall use it only in accordance with the terms of the
00012 * license agreement you entered into with Oracle.
00013 *
00014 * This notice may not be removed or altered.
00015 */
00016 #ifndef COH_RAW_DATE_HPP
00017 #define COH_RAW_DATE_HPP
00018 
00019 #include "coherence/lang.ns"
00020 
00021 #include <ostream>
00022 #include <time.h>
00023 
00024 COH_OPEN_NAMESPACE3(coherence,io,pof)
00025 
00026 
00027 /**
00028 * Raw immutable POF date value.
00029 *
00030 * @author jh  2008.04.08
00031 */
00032 class COH_EXPORT RawDate
00033     : public cloneable_spec<RawDate>
00034     {
00035     friend class factory<RawDate>;
00036 
00037     // ----- typedefs -------------------------------------------------------
00038 
00039     public:
00040         /**
00041         * The boxed native type.
00042         */
00043         typedef struct tm BoxedType;
00044 
00045 
00046     // ----- constructors ---------------------------------------------------
00047 
00048     protected:
00049         /**
00050         * Construct a raw POF date value.
00051         *
00052         * @param nYear   the year number as defined by ISO8601
00053         * @param nMonth  the month number between 1 and 12 inclusive as
00054         *                defined by ISO8601
00055         * @param nDay    the day number between 1 and 31 inclusive as defined
00056         *                by ISO8601
00057         *
00058         * @return the new RawDate
00059         */
00060         RawDate(int32_t nYear, int32_t nMonth, int32_t nDay);
00061 
00062         /**
00063         * Construct a raw POF date value from a POSIX datetime struct.
00064         */
00065         RawDate(const struct tm& timeinfo);
00066 
00067         /**
00068         * Copy constructor.
00069         */
00070         RawDate(const RawDate& that);
00071 
00072 
00073     // ----- Object interface -----------------------------------------------
00074 
00075     public:
00076         /**
00077         * {@inheritDoc}
00078         */
00079         virtual bool equals(Object::View v) const;
00080 
00081         /**
00082         * {@inheritDoc}
00083         */
00084         virtual size32_t hashCode() const;
00085 
00086         /**
00087         * {@inheritDoc}
00088         */
00089         virtual bool isImmutable() const;
00090 
00091         /**
00092         * {@inheritDoc}
00093         */
00094         virtual void toStream(std::ostream &out) const;
00095 
00096 
00097     // ----- accessors ------------------------------------------------------
00098 
00099     public:
00100         /**
00101         * Determine the date's year value.
00102         *
00103         * @return the year number as defined by ISO8601
00104         */
00105         virtual int32_t getYear() const;
00106 
00107         /**
00108         * Determine the date's month value.
00109         *
00110         * @return the month number between 1 and 12 inclusive as defined by
00111         *         ISO8601
00112         */
00113         virtual int32_t getMonth() const;
00114 
00115         /**
00116         * Determine the date's day value.
00117         *
00118         * @return the day number between 1 and 31 inclusive as defined by
00119         *         ISO8601
00120         */
00121         virtual int32_t getDay() const;
00122 
00123         /**
00124         * Convert the RawDate to a POSIX datetime struct.
00125         */
00126         virtual operator struct tm() const;
00127 
00128     // ----- data members ---------------------------------------------------
00129 
00130     protected:
00131         /**
00132         * The year number.
00133         */
00134         int32_t m_nYear;
00135 
00136         /**
00137         * The month number.
00138         */
00139         int32_t m_nMonth;
00140 
00141         /**
00142         * The day number.
00143         */
00144         int32_t m_nDay;
00145     };
00146 
00147 COH_CLOSE_NAMESPACE3
00148 
00149 #endif // COH_RAW_DATE_HPP
Copyright (c) 2000, 2009, Oracle and/or its affiliates. All rights reserved.