Changeset 681
- Timestamp:
- 05/06/08 20:26:15 (7 months ago)
- Files:
-
- 1 modified
-
trunk/include/liblas/guid.hpp (modified) (26 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/liblas/guid.hpp
r651 r681 4 4 * Project: libLAS - http://liblas.org - A BSD library for LAS format data. 5 5 * Purpose: GUID implementation 6 * Author: Mateusz Loskot, mateusz@loskot.net6 * Author: Andy Tompkins (modified by Mateusz Loskot) 7 7 * 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 10 11 * 11 12 * (C) Copyright 2006 Andy Tompkins. … … 76 77 namespace liblas { 77 78 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 79 88 class guid 80 89 { 81 90 public: 82 91 92 /// Default constructor initializes GUID as null. 93 /// \exception nothrow 94 /// \post guid::is_null() == true. 83 95 guid() /* throw() */ 84 96 { … … 86 98 } 87 99 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. 88 104 explicit guid(char const* const str) 89 105 { … … 93 109 } 94 110 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. 95 115 template <typename ch, typename char_traits, typename alloc> 96 116 explicit guid(std::basic_string<ch, char_traits, alloc> const& str) … … 99 119 } 100 120 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. 101 128 guid(liblas::uint32_t const& d1, liblas::uint16_t const& d2, liblas::uint16_t const& d3, liblas::uint8_t const (&d4)[8]) 102 129 { … … 104 131 } 105 132 133 /// Copy constructor. 134 /// \exception nothrow 106 135 guid(guid const& rhs) /* throw() */ 107 136 { … … 109 138 } 110 139 140 /// Destructor. 141 /// \exception nothrow 111 142 ~guid() /* throw() */ 112 143 {} 113 144 145 /// Assignment operator. 146 /// \exception nothrow 114 147 guid& operator=(guid const& rhs) /* throw() */ 115 148 { … … 121 154 } 122 155 156 /// Equality operator. 157 /// \exception nothrow 123 158 bool operator==(guid const& rhs) const /* throw() */ 124 159 { … … 126 161 } 127 162 163 /// Inequality operator. 164 /// \exception nothrow 128 165 bool operator!=(guid const& rhs) const /* throw() */ 129 166 { … … 131 168 } 132 169 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 133 175 bool operator<(guid const& rhs) const /* throw() */ 134 176 { … … 136 178 } 137 179 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 138 185 bool operator>(guid const& rhs) const /* throw() */ 139 186 { … … 141 188 } 142 189 190 /// Less-than-or-equal-to operator. 191 /// \param rhs - GUID object on the right-hand side of the comparison. 192 /// \exception nothrow 143 193 bool operator<=(guid const& rhs) const /* throw() */ 144 194 { … … 146 196 } 147 197 198 /// More-than-or-equal-to operator. 199 /// \param rhs - GUID object on the right-hand side of the comparison. 200 /// \exception nothrow 148 201 bool operator>=(guid const& rhs) const /* throw() */ 149 202 { … … 151 204 } 152 205 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 153 210 bool is_null() const /* throw() */ 154 211 { … … 156 213 } 157 214 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. 158 220 std::string to_string() const 159 221 { … … 161 223 } 162 224 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. 163 228 template <typename ch, typename char_traits, typename alloc> 164 229 std::basic_string<ch, char_traits, alloc> to_basic_string() const … … 172 237 throw std::runtime_error("failed to convert guid to string"); 173 238 } 239 240 assert(!s.empty()); 174 241 return s; 175 242 } 176 243 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). 177 247 size_t byte_count() const /* throw() */ 178 248 { … … 180 250 } 181 251 252 253 /// Send bytes of GUID data to sequenec of bytes using given output iterator. 254 /// \exception nothrow 182 255 template <typename ByteOutputIterator> 183 256 void output_bytes(ByteOutputIterator out) const … … 186 259 } 187 260 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 188 267 void output_data(liblas::uint32_t& d1, liblas::uint16_t& d2, liblas::uint16_t& d3, liblas::uint8_t (&d4)[8]) const 189 268 { … … 217 296 } 218 297 298 /// Null GUID number generator. 299 /// \return null-initialized instance of GUID number. 300 /// \exception nothrow 219 301 static guid const& null() /* throw() */ 220 302 { … … 223 305 } 224 306 307 /// Random GUID number generator. 308 /// \return random-initialized instance of GUID number. 309 /// \exception nothrow 225 310 static guid create() 226 311 { … … 228 313 } 229 314 315 /// Create GUID number based on calculation of SHA1 has for given name. 316 /// \exception std::runtime_error on GUID creation failure. 230 317 static guid create(guid const& namespace_guid, char const* name, int name_length) 231 318 { … … 233 320 } 234 321 322 /// Return flag indicating if bracket text form of GUID on output is set. 323 /// \exception nothrow 235 324 static inline bool get_showbraces(std::ios_base & iosbase) 236 325 { 237 326 return (iosbase.iword(get_showbraces_index()) != 0); 238 327 } 328 329 /// Request to bracket text form of GUID on output. 330 /// \exception nothrow 239 331 static inline void set_showbraces(std::ios_base & iosbase, bool showbraces) 240 332 { … … 242 334 } 243 335 336 /// Request to bracket text form of GUID on output. 337 /// \exception nothrow 244 338 static inline std::ios_base& showbraces(std::ios_base& iosbase) 245 339 { … … 253 347 } 254 348 349 /// Overloaded output stream operator for guid type. 255 350 friend std::ostream& operator<<(std::ostream& os, guid const& g); 351 352 /// Overloaded input stream operator for guid type. 256 353 friend std::istream& operator>>(std::istream& is, guid &g); 257 354 … … 303 400 304 401 //random number based 305 static guid create_random_based() 402 static guid create_random_based() // throw() 306 403 { 307 404 guid result;
