Changeset 681

Show
Ignore:
Timestamp:
05/06/08 20:26:15 (7 months ago)
Author:
mloskot
Message:

Documented liblas::guid class (Ticket #45).

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/include/liblas/guid.hpp

    r651 r681  
    44 * Project:  libLAS - http://liblas.org - A BSD library for LAS format data. 
    55 * Purpose:  GUID implementation 
    6  * Author:   Mateusz Loskot, mateusz@loskot.net 
     6 * Author:   Andy Tompkins (modified by Mateusz Loskot) 
    77 * 
    8  * This file has been stolen from <boost/cstdint.hpp> and 
    9  * modified for libLAS purposes. 
     8 * This file has been stolen from the Boost Vault and 
     9 * modified for libLAS purposes. Here is the original code posted: 
     10 * http://lists.boost.org/boost-users/2007/04/27397.php 
    1011 *  
    1112 * (C) Copyright 2006 Andy Tompkins. 
     
    7677namespace liblas { 
    7778 
    78 /// \todo To be documented. 
     79/// Definition of Globally Unique Identifier type. 
     80/// The GUID is a 16-byte (128-bit) number. 
     81/// This class is used to represent value stored as Project Identifier 
     82/// in public header block (see LASHeader) of a LAS file. 
     83/// All files in a unique project should have the same value of 
     84/// the Project Identifier. It is used together with File Source ID to 
     85/// uniquely identify every LAS, globally. 
     86/// 
     87/// \see About GUID in Wikipedia http://en.wikipedia.org/wiki/Globally_Unique_Identifier  
    7988class guid 
    8089{ 
    8190public: 
    8291 
     92    /// Default constructor initializes GUID as null. 
     93    /// \exception nothrow 
     94    /// \post guid::is_null() == true. 
    8395    guid() /* throw() */ 
    8496    { 
     
    8698    } 
    8799 
     100    /// Initializes from textual representation of valid GUID. 
     101    /// \param str - non-null pointer to string with GUID text. 
     102    /// \exception std::invalid_argument if construction failed. 
     103    /// \post guid::is_null() == false. 
    88104    explicit guid(char const* const str) 
    89105    { 
     
    93109    } 
    94110 
     111    /// Initializes from textual representation of valid GUID. 
     112    /// \param str - string with GUID text. 
     113    /// \exception std::invalid_argument if construction failed. 
     114    /// \post guid::is_null() == false. 
    95115    template <typename ch, typename char_traits, typename alloc> 
    96116    explicit guid(std::basic_string<ch, char_traits, alloc> const& str) 
     
    99119    } 
    100120 
     121    /// Initializes from 4-fields structure. 
     122    /// \param d1 - field of first 32 bits of GUID number. 
     123    /// \param d2 - field of subsequent 16 bits of GUID number. 
     124    /// \param d3 - third field of 16 bits of GUID number. 
     125    /// \param d4 - last 64 bits of GUID number. 
     126    /// \exception std::invalid_argument if construction failed. 
     127    /// \post guid::is_null() == false. 
    101128    guid(liblas::uint32_t const& d1, liblas::uint16_t const& d2, liblas::uint16_t const& d3, liblas::uint8_t const (&d4)[8]) 
    102129    { 
     
    104131    } 
    105132 
     133    /// Copy constructor. 
     134    /// \exception nothrow 
    106135    guid(guid const& rhs) /* throw() */ 
    107136    { 
     
    109138    } 
    110139 
     140    /// Destructor. 
     141    /// \exception nothrow 
    111142    ~guid() /* throw() */ 
    112143    {} 
    113144 
     145    /// Assignment operator. 
     146    /// \exception nothrow 
    114147    guid& operator=(guid const& rhs) /* throw() */ 
    115148    { 
     
    121154    } 
    122155 
     156    /// Equality operator. 
     157    /// \exception nothrow 
    123158    bool operator==(guid const& rhs) const /* throw() */ 
    124159    { 
     
    126161    } 
    127162 
     163    /// Inequality operator. 
     164    /// \exception nothrow 
    128165    bool operator!=(guid const& rhs) const /* throw() */ 
    129166    { 
     
    131168    } 
    132169 
     170    /// Less-than operator. 
     171    /// \param rhs - GUID object on the right-hand side of the comparison. 
     172    /// \return true if the GUID on the left-hand side is lexicographically less 
     173    /// than GUID on the right side; false otherwise. 
     174    /// \exception nothrow 
    133175    bool operator<(guid const& rhs) const /* throw() */ 
    134176    { 
     
    136178    } 
    137179     
     180    /// More-than operator. 
     181    /// \param rhs - GUID object on the right-hand side of the comparison. 
     182    /// \return true if the GUID on the left-hand side is not lexicographically less 
     183    /// than GUID on the right side; false otherwise. 
     184    /// \exception nothrow 
    138185    bool operator>(guid const& rhs) const /* throw() */ 
    139186    { 
     
    141188    } 
    142189 
     190    /// Less-than-or-equal-to operator. 
     191    /// \param rhs - GUID object on the right-hand side of the comparison. 
     192    /// \exception nothrow 
    143193    bool operator<=(guid const& rhs) const /* throw() */ 
    144194    { 
     
    146196    } 
    147197 
     198    /// More-than-or-equal-to operator. 
     199    /// \param rhs - GUID object on the right-hand side of the comparison. 
     200    /// \exception nothrow 
    148201    bool operator>=(guid const& rhs) const /* throw() */ 
    149202    { 
     
    151204    } 
    152205 
     206    /// Test if the GUID object is null GUID or not. 
     207    /// Null means GUID number value is Zero. 
     208    /// \return true if the GUID is null; false otherwise 
     209    /// \exception nothrow 
    153210    bool is_null() const /* throw() */ 
    154211    { 
     
    156213    } 
    157214 
     215    /// Generate textual representation of the GUID number. 
     216    /// Specialization for std::string type. 
     217    /// \return string with textual representation of GUID 
     218    /// \exception std::runtime_error - thrown on GUID to string conversion failure 
     219    /// \post guid::to_string().empty() == false. 
    158220    std::string to_string() const 
    159221    { 
     
    161223    } 
    162224     
     225    /// Generic generator of textual representation of the GUID number. 
     226    /// \exception std::runtime_error - thrown on GUID to string conversion failure 
     227    /// \post guid::to_basic_string().empty() == false. 
    163228    template <typename ch, typename char_traits, typename alloc> 
    164229    std::basic_string<ch, char_traits, alloc> to_basic_string() const 
     
    172237            throw std::runtime_error("failed to convert guid to string"); 
    173238        } 
     239 
     240        assert(!s.empty()); 
    174241        return s; 
    175242    } 
    176243 
     244    /// Size of the GUID number in bytes. 
     245    /// \return The number of bytes is constant for all GUID objects 
     246    /// and equal to 16 bytes (128-bit number). 
    177247    size_t byte_count() const /* throw() */ 
    178248    { 
     
    180250    } 
    181251 
     252 
     253    /// Send bytes of GUID data to sequenec of bytes using given output iterator. 
     254    /// \exception nothrow 
    182255    template <typename ByteOutputIterator> 
    183256    void output_bytes(ByteOutputIterator out) const 
     
    186259    } 
    187260 
     261    /// Separate bytes of GUID data to distinct buffers. 
     262    /// \param d1 - buffer for first 32 bits of GUID number. 
     263    /// \param d2 - buffer for 16 bits of second chunk of GUID number. 
     264    /// \param d3 - buffer for 16 bits of third chunk of GUID number. 
     265    /// \param d4 - buffer for last 64 bits of GUID number. 
     266    /// \exception nothrow 
    188267    void output_data(liblas::uint32_t& d1, liblas::uint16_t& d2, liblas::uint16_t& d3, liblas::uint8_t (&d4)[8]) const 
    189268    { 
     
    217296    } 
    218297 
     298    /// Null GUID number generator. 
     299    /// \return null-initialized instance of GUID number. 
     300    /// \exception nothrow 
    219301    static guid const& null() /* throw() */ 
    220302    { 
     
    223305    } 
    224306 
     307    /// Random GUID number generator. 
     308    /// \return random-initialized instance of GUID number. 
     309    /// \exception nothrow 
    225310    static guid create() 
    226311    { 
     
    228313    } 
    229314     
     315    /// Create GUID number based on calculation of SHA1 has for given name. 
     316    /// \exception std::runtime_error on GUID creation failure. 
    230317    static guid create(guid const& namespace_guid, char const* name, int name_length) 
    231318    { 
     
    233320    } 
    234321 
     322    /// Return flag indicating if bracket text form of GUID on output is set. 
     323    /// \exception nothrow 
    235324    static inline bool get_showbraces(std::ios_base & iosbase) 
    236325    { 
    237326        return (iosbase.iword(get_showbraces_index()) != 0); 
    238327    } 
     328 
     329    /// Request to bracket text form of GUID on output. 
     330    /// \exception nothrow 
    239331    static inline void set_showbraces(std::ios_base & iosbase, bool showbraces) 
    240332    { 
     
    242334    } 
    243335 
     336    /// Request to bracket text form of GUID on output. 
     337    /// \exception nothrow 
    244338    static inline std::ios_base& showbraces(std::ios_base& iosbase) 
    245339    { 
     
    253347    } 
    254348     
     349    /// Overloaded output stream operator for guid type. 
    255350    friend std::ostream& operator<<(std::ostream& os, guid const& g); 
     351 
     352    /// Overloaded input stream operator for guid type. 
    256353    friend std::istream& operator>>(std::istream& is, guid &g); 
    257354 
     
    303400 
    304401    //random number based 
    305     static guid create_random_based() 
     402    static guid create_random_based() // throw() 
    306403    { 
    307404        guid result;