- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# D:/Programmation/Sources/Tensor2/Utils/include/frost_utils_bool.h

Go to the documentation of this file.

    00001 // Warning : If you need to use this file, include frost_utils_types.h
    00002 namespace Frost
    00003 {
    00004     /// Base type : boolean
    00005     /** Frost's base types are made to allow simpler
    00006     *   manipulation of numbers, booleans and strings.
    00007     *   They simplify conversions (mostly to string),
    00008     *   allow easy access to math/string functions and
    00009     *   implements new functions that are not present
    00010     *   in the standard libraries.
    00011     *   \note This class doesn't need to be a template,
    00012     *         as there is only one boolean type in C++.
    00013     *         But it is delays the compilation of the
    00014     *         class.
    00015     */
    00016     template<class T>
    00017     class s_bool_t
    00018     {
    00019     public :
    00020
    00021         s_bool_t();
    00022
    00023         s_bool_t(const T& bValue);
    00024
    00025         template<class N>
    00026         explicit s_bool_t(const s_str_t<N>& sValue)
    00027         {
    00028             bValue_ = ((sValue == BOOL_TRUE) ||
    00029                        (sValue == BOOL_ONE)  ||
    00030                        (sValue == BOOL_YES));
    00031         }
    00032
    00033         /// Returns a const reference to the boolean.
    00034         /** \return A const reference to the boolean
    00035         */
    00036         inline const T& Get() const { return bValue_; }
    00037
    00038         /// Returns a reference to the boolean.
    00039         /** \return A reference to the boolean
    00040         */
    00041         inline T& GetR() { return bValue_; }
    00042
    00043         bool operator ! () const;
    00044
    00045         typedef const bool& (s_bool_t::*MemberFn)() const;
    00046         operator MemberFn() const;
    00047
    00048         s_bool_t operator == (const s_bool_t& bValue) const;
    00049
    00050         s_bool_t operator != (const s_bool_t& bValue) const;
    00051
    00052         s_bool_t& operator =  (const s_bool_t& bValue);
    00053
    00054         static const string_element* BOOL_TRUE;
    00055         static const string_element* BOOL_ONE;
    00056         static const string_element* BOOL_YES;
    00057         static T                     bDummy;
    00058
    00059         /// Returns a random boolean.
    00060         /** \return Either 'true' or 'false' (50% each).
    00061         */
    00062         static s_bool_t Random();
    00063
    00064     private :
    00065
    00066         T bValue_;
    00067     };
    00068
    00069     typedef s_bool_t<bool> s_bool;
    00070
    00071     /** \cond NOT_REMOVE_FROM_DOC
    00072     */
    00073     template<> class TypeTraits<bool>
    00074     {
    00075     public :
    00076         typedef bool        Type;
    00077         typedef bool        BaseType;
    00078         typedef s_bool      FrostType;
    00079         typedef bool&       RefType;
    00080         typedef const bool& CRefType;
    00081         typedef bool*       PointerType;
    00082
    00083         static inline RefType  GetValue(RefType  m) { return m; }
    00084         static inline CRefType GetValue(CRefType m) { return m; }
    00085     };
    00086
    00087     template<> class TypeTraits<s_bool>
    00088     {
    00089     public :
    00090         typedef s_bool        Type;
    00091         typedef bool          BaseType;
    00092         typedef s_bool        FrostType;
    00093         typedef s_bool&       RefType;
    00094         typedef const s_bool& CRefType;
    00095         typedef s_bool*       PointerType;
    00096
    00097         static inline bool&       GetValue(RefType m)  { return m.GetR(); }
    00098         static inline const bool& GetValue(CRefType m) { return m.Get(); }
    00099     };
    00100     /** \endcond
    00101     */
    00102 }