DriveHQ Start Menu
Cloud Drive Mapping
Folder Sync
Cloud Backup
True Drop Box
FTP/SFTP Hosting
Group Account
DriveHQ Start Menu
Online File Server
My Storage
|
Manage Shares
|
Publishes
|
Drop Boxes
|
Group Account
WebDAV Drive Mapping
Cloud Drive Home
|
WebDAV Guide
|
Drive Mapping Tool
|
Drive Mapping URL
Complete Data Backup
Backup Guide
|
Online Backup Tool
|
Cloud-to-Cloud Backup
FTP, Email & Web Service
FTP Home
|
FTP Hosting FAQ
|
Email Hosting
|
EmailManager
|
Web Hosting
Help & Resources
About
|
Enterprise Service
|
Partnership
|
Comparisons
|
Support
Quick Links
Security and Privacy
Download Software
Service Manual
Use Cases
Group Account
Online Help
Blog
Contact
Cloud Surveillance
Sign Up
Login
Features
Business Features
Online File Server
FTP Hosting
Cloud Drive Mapping
Cloud File Backup
Email Backup & Hosting
Cloud File Sharing
Folder Synchronization
Group Management
True Drop Box
Full-text Search
AD Integration/SSO
Mobile Access
IP Camera & DVR Solution
More...
Personal Features
Personal Cloud Drive
Backup All Devices
Mobile APPs
Personal Web Hosting
Sub-Account (for Kids)
Home/PC/Kids Monitoring
More...
Software
DriveHQ Drive Mapping Tool
DriveHQ FileManager
DriveHQ Online Backup
DriveHQ Mobile Apps
Pricing
Business Plans & Pricing
Personal Plans & Pricing
Price Comparison with Others
Feature Comparison with Others
Install Mobile App
Sign up
Creating account...
Invalid character in username! Only 0-9, a-z, A-Z, _, -, . allowed.
Username is required!
Invalid email address!
E-mail is required!
Password is required!
Password is invalid!
Password and confirmation do not match.
Confirm password is required!
I accept
Membership Agreement
Please read the Membership Agreement and check "I accept"!
Free Quick Sign-up
Sign-up Page
Log in
Signing in...
Username or e-mail address is required!
Password is required!
Keep me logged in
Quick Login
Forgot Password
Up
Upload
Download
Share
Publish
New Folder
New File
Copy
Cut
Delete
Paste
Rate
Upgrade
Rotate
Effect
Edit
Slide
History
#ifndef _DATE_TIME_INT_ADAPTER_HPP__ #define _DATE_TIME_INT_ADAPTER_HPP__ /* Copyright (c) 2002,2003 CrystalClear Software, Inc. * Use, modification and distribution is subject to the * Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) * Author: Jeff Garland, Bart Garst * $Date: 2008-02-27 15:00:24 -0500 (Wed, 27 Feb 2008) $ */ #include "boost/config.hpp" #include "boost/limits.hpp" //work around compilers without limits #include "boost/date_time/special_defs.hpp" #include "boost/date_time/locale_config.hpp" #include
namespace boost { namespace date_time { //! Adapter to create integer types with +-infinity, and not a value /*! This class is used internally in counted date/time representations. * It adds the floating point like features of infinities and * not a number. It also provides mathmatical operations with * consideration to special values following these rules: *@code * +infinity - infinity == Not A Number (NAN) * infinity * non-zero == infinity * infinity * zero == NAN * +infinity * -integer == -infinity * infinity / infinity == NAN * infinity * infinity == infinity *@endcode */ template
class int_adapter { public: typedef int_type_ int_type; int_adapter(int_type v) : value_(v) {} static bool has_infinity() { return true; } static const int_adapter pos_infinity() { return (::std::numeric_limits
::max)(); } static const int_adapter neg_infinity() { return (::std::numeric_limits
::min)(); } static const int_adapter not_a_number() { return (::std::numeric_limits
::max)()-1; } static int_adapter max BOOST_PREVENT_MACRO_SUBSTITUTION () { return (::std::numeric_limits
::max)()-2; } static int_adapter min BOOST_PREVENT_MACRO_SUBSTITUTION () { return (::std::numeric_limits
::min)()+1; } static int_adapter from_special(special_values sv) { switch (sv) { case not_a_date_time: return not_a_number(); case neg_infin: return neg_infinity(); case pos_infin: return pos_infinity(); case max_date_time: return (max)(); case min_date_time: return (min)(); default: return not_a_number(); } } static bool is_inf(int_type v) { return (v == neg_infinity().as_number() || v == pos_infinity().as_number()); } static bool is_neg_inf(int_type v) { return (v == neg_infinity().as_number()); } static bool is_pos_inf(int_type v) { return (v == pos_infinity().as_number()); } static bool is_not_a_number(int_type v) { return (v == not_a_number().as_number()); } //! Returns either special value type or is_not_special static special_values to_special(int_type v) { if (is_not_a_number(v)) return not_a_date_time; if (is_neg_inf(v)) return neg_infin; if (is_pos_inf(v)) return pos_infin; return not_special; } //-3 leaves room for representations of infinity and not a date static int_type maxcount() { return (::std::numeric_limits
::max)()-3; } bool is_infinity() const { return (value_ == neg_infinity().as_number() || value_ == pos_infinity().as_number()); } bool is_pos_infinity()const { return(value_ == pos_infinity().as_number()); } bool is_neg_infinity()const { return(value_ == neg_infinity().as_number()); } bool is_nan() const { return (value_ == not_a_number().as_number()); } bool is_special() const { return(is_infinity() || is_nan()); } bool operator==(const int_adapter& rhs) const { return (compare(rhs) == 0); } bool operator==(const int& rhs) const { // quiets compiler warnings bool is_signed = std::numeric_limits
::is_signed; if(!is_signed) { if(is_neg_inf(value_) && rhs == 0) { return false; } } return (compare(rhs) == 0); } bool operator!=(const int_adapter& rhs) const { return (compare(rhs) != 0); } bool operator!=(const int& rhs) const { // quiets compiler warnings bool is_signed = std::numeric_limits
::is_signed; if(!is_signed) { if(is_neg_inf(value_) && rhs == 0) { return true; } } return (compare(rhs) != 0); } bool operator<(const int_adapter& rhs) const { return (compare(rhs) == -1); } bool operator<(const int& rhs) const { // quiets compiler warnings bool is_signed = std::numeric_limits
::is_signed; if(!is_signed) { if(is_neg_inf(value_) && rhs == 0) { return true; } } return (compare(rhs) == -1); } bool operator>(const int_adapter& rhs) const { return (compare(rhs) == 1); } int_type as_number() const { return value_; } //! Returns either special value type or is_not_special special_values as_special() const { return int_adapter::to_special(value_); } //creates nasty ambiguities // operator int_type() const // { // return value_; // } /*! Operator allows for adding dissimilar int_adapter types. * The return type will match that of the the calling object's type */ template
inline int_adapter operator+(const int_adapter
& rhs) const { if(is_special() || rhs.is_special()) { if (is_nan() || rhs.is_nan()) { return int_adapter::not_a_number(); } if((is_pos_inf(value_) && rhs.is_neg_inf(rhs.as_number())) || (is_neg_inf(value_) && rhs.is_pos_inf(rhs.as_number())) ) { return int_adapter::not_a_number(); } if (is_infinity()) { return *this; } if (rhs.is_pos_inf(rhs.as_number())) { return int_adapter::pos_infinity(); } if (rhs.is_neg_inf(rhs.as_number())) { return int_adapter::neg_infinity(); } } return int_adapter
(value_ + rhs.as_number()); } int_adapter operator+(const int_type rhs) const { if(is_special()) { if (is_nan()) { return int_adapter
(not_a_number()); } if (is_infinity()) { return *this; } } return int_adapter
(value_ + rhs); } /*! Operator allows for subtracting dissimilar int_adapter types. * The return type will match that of the the calling object's type */ template
inline int_adapter operator-(const int_adapter
& rhs)const { if(is_special() || rhs.is_special()) { if (is_nan() || rhs.is_nan()) { return int_adapter::not_a_number(); } if((is_pos_inf(value_) && rhs.is_pos_inf(rhs.as_number())) || (is_neg_inf(value_) && rhs.is_neg_inf(rhs.as_number())) ) { return int_adapter::not_a_number(); } if (is_infinity()) { return *this; } if (rhs.is_pos_inf(rhs.as_number())) { return int_adapter::neg_infinity(); } if (rhs.is_neg_inf(rhs.as_number())) { return int_adapter::pos_infinity(); } } return int_adapter
(value_ - rhs.as_number()); } int_adapter operator-(const int_type rhs) const { if(is_special()) { if (is_nan()) { return int_adapter
(not_a_number()); } if (is_infinity()) { return *this; } } return int_adapter
(value_ - rhs); } // should templatize this to be consistant with op +- int_adapter operator*(const int_adapter& rhs)const { if(this->is_special() || rhs.is_special()) { return mult_div_specials(rhs); } return int_adapter
(value_ * rhs.value_); } /*! Provided for cases when automatic conversion from * 'int' to 'int_adapter' causes incorrect results. */ int_adapter operator*(const int rhs) const { if(is_special()) { return mult_div_specials(rhs); } return int_adapter
(value_ * rhs); } // should templatize this to be consistant with op +- int_adapter operator/(const int_adapter& rhs)const { if(this->is_special() || rhs.is_special()) { if(is_infinity() && rhs.is_infinity()) { return int_adapter
(not_a_number()); } if(rhs != 0) { return mult_div_specials(rhs); } else { // let divide by zero blow itself up return int_adapter
(value_ / rhs.value_); } } return int_adapter
(value_ / rhs.value_); } /*! Provided for cases when automatic conversion from * 'int' to 'int_adapter' causes incorrect results. */ int_adapter operator/(const int rhs) const { if(is_special() && rhs != 0) { return mult_div_specials(rhs); } return int_adapter
(value_ / rhs); } // should templatize this to be consistant with op +- int_adapter operator%(const int_adapter& rhs)const { if(this->is_special() || rhs.is_special()) { if(is_infinity() && rhs.is_infinity()) { return int_adapter
(not_a_number()); } if(rhs != 0) { return mult_div_specials(rhs); } else { // let divide by zero blow itself up return int_adapter
(value_ % rhs.value_); } } return int_adapter
(value_ % rhs.value_); } /*! Provided for cases when automatic conversion from * 'int' to 'int_adapter' causes incorrect results. */ int_adapter operator%(const int rhs) const { if(is_special() && rhs != 0) { return mult_div_specials(rhs); } return int_adapter
(value_ % rhs); } private: int_type value_; //! returns -1, 0, 1, or 2 if 'this' is <, ==, >, or 'nan comparison' rhs int compare(const int_adapter& rhs)const { if(this->is_special() || rhs.is_special()) { if(this->is_nan() || rhs.is_nan()) { if(this->is_nan() && rhs.is_nan()) { return 0; // equal } else { return 2; // nan } } if((is_neg_inf(value_) && !is_neg_inf(rhs.value_)) || (is_pos_inf(rhs.value_) && !is_pos_inf(value_)) ) { return -1; // less than } if((is_pos_inf(value_) && !is_pos_inf(rhs.value_)) || (is_neg_inf(rhs.value_) && !is_neg_inf(value_)) ) { return 1; // greater than } } if(value_ < rhs.value_) return -1; if(value_ > rhs.value_) return 1; // implied-> if(value_ == rhs.value_) return 0; } /* When multiplying and dividing with at least 1 special value * very simmilar rules apply. In those cases where the rules * are different, they are handled in the respective operator * function. */ //! Assumes at least 'this' or 'rhs' is a special value int_adapter mult_div_specials(const int_adapter& rhs)const { int min_value; // quiets compiler warnings bool is_signed = std::numeric_limits
::is_signed; if(is_signed) { min_value = 0; } else { min_value = 1;// there is no zero with unsigned } if(this->is_nan() || rhs.is_nan()) { return int_adapter
(not_a_number()); } if((*this > 0 && rhs > 0) || (*this < min_value && rhs < min_value)) { return int_adapter
(pos_infinity()); } if((*this > 0 && rhs < min_value) || (*this < min_value && rhs > 0)) { return int_adapter
(neg_infinity()); } //implied -> if(this->value_ == 0 || rhs.value_ == 0) return int_adapter
(not_a_number()); } /* Overloaded function necessary because of special * situation where int_adapter is instantiated with * 'unsigned' and func is called with negative int. * It would produce incorrect results since 'unsigned' * wraps around when initialized with a negative value */ //! Assumes 'this' is a special value int_adapter mult_div_specials(const int& rhs) const { int min_value; // quiets compiler warnings bool is_signed = std::numeric_limits
::is_signed; if(is_signed) { min_value = 0; } else { min_value = 1;// there is no zero with unsigned } if(this->is_nan()) { return int_adapter
(not_a_number()); } if((*this > 0 && rhs > 0) || (*this < min_value && rhs < 0)) { return int_adapter
(pos_infinity()); } if((*this > 0 && rhs < 0) || (*this < min_value && rhs > 0)) { return int_adapter
(neg_infinity()); } //implied -> if(this->value_ == 0 || rhs.value_ == 0) return int_adapter
(not_a_number()); } }; #ifndef BOOST_DATE_TIME_NO_LOCALE /*! Expected output is either a numeric representation * or a special values representation.
* Ex. "12", "+infinity", "not-a-number", etc. */ //template
, typename int_type> template
inline std::basic_ostream
& operator<<(std::basic_ostream
& os, const int_adapter
& ia) { if(ia.is_special()) { // switch copied from date_names_put.hpp switch(ia.as_special()) { case not_a_date_time: os << "not-a-number"; break; case pos_infin: os << "+infinity"; break; case neg_infin: os << "-infinity"; break; default: os << ""; } } else { os << ia.as_number(); } return os; } #endif } } //namespace date_time #endif
int_adapter.hpp
Page URL
File URL
Prev
28/60
Next
Download
( 13 KB )
Note: The DriveHQ service banners will NOT be displayed if the file owner is a paid member.
Comments
Total ratings:
0
Average rating:
Not Rated
Would you like to comment?
Join DriveHQ
for a free account, or
Logon
if you are already a member.