ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
Common.h
Go to the documentation of this file.
1 /*
2  * Original work Copyright 2009 - 2010 Kevin Ackley (kackley@gwi.net)
3  * Modified work Copyright 2018 - 2020 Andy Maloney <asmaloney@gmail.com>
4  *
5  * Permission is hereby granted, free of charge, to any person or organization
6  * obtaining a copy of the software and accompanying documentation covered by
7  * this license (the "Software") to use, reproduce, display, distribute,
8  * execute, and transmit the Software, and to prepare derivative works of the
9  * Software, and to permit third-parties to whom the Software is furnished to
10  * do so, all subject to the following:
11  *
12  * The copyright notices in the Software and this entire statement, including
13  * the above license grant, this restriction and the following disclaimer,
14  * must be included in all copies of the Software, in whole or in part, and
15  * all derivative works of the Software, unless such copies or derivative
16  * works are solely in the form of machine-executable object code generated by
17  * a source language processor.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
22  * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
23  * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
24  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25  * DEALINGS IN THE SOFTWARE.
26  */
27 
28 #pragma once
29 
30 #include <iomanip>
31 #include <iostream>
32 #include <set>
33 #include <sstream>
34 #include <string>
35 #include <vector>
36 
37 // Define the following symbol adds some functions to the API for implementation
38 // purposes. These functions are not available to a normal API user.
39 #define E57_INTERNAL_IMPLEMENTATION_ENABLE 1
40 #include "E57Format.h"
41 
42 // Uncomment the lines below to enable various levels of cross checking and
43 // verification in the code. The extra code does not change the file contents.
44 // Recommend that E57_DEBUG remain defined even for production versions.
45 #define E57_DEBUG 1
46 // #define E57_MAX_DEBUG 1
47 
48 // Uncomment the lines below to enable various levels of printing to the console
49 // of what is going on in the code.
50 // #define E57_VERBOSE 1
51 // #define E57_MAX_VERBOSE 1
52 
53 // Uncomment the line below to enable writing packets that are correct but will
54 // stress the reader.
55 // #define E57_WRITE_CRAZY_PACKET_MODE 1
56 
57 #ifdef _MSC_VER
58 // Disable MSVC warning: warning C4224: nonstandard extension used : formal
59 // parameter 'locale' was previously defined as a type
60 #pragma warning( disable : 4224 )
61 #endif
62 
63 namespace e57
64 {
66 #define E57_EXCEPTION1( ecode ) \
67  ( E57Exception( ( ecode ), ustring(), __FILE__, __LINE__, static_cast<const char *>( __FUNCTION__ ) ) )
68 #define E57_EXCEPTION2( ecode, context ) \
69  ( E57Exception( ( ecode ), ( context ), __FILE__, __LINE__, static_cast<const char *>( __FUNCTION__ ) ) )
70 
73  inline std::string space( size_t n )
74  {
75  return ( std::string( n, ' ' ) );
76  }
77 
80  template <class T> std::string toString( T x )
81  {
82  std::ostringstream ss;
83  ss << x;
84  return ( ss.str() );
85  }
86 
87  inline std::string hexString( uint64_t x )
88  {
89  std::ostringstream ss;
90  ss << "0x" << std::hex << std::setw( 16 ) << std::setfill( '0' ) << x;
91  return ( ss.str() );
92  }
93  inline std::string hexString( uint32_t x )
94  {
95  std::ostringstream ss;
96  ss << "0x" << std::hex << std::setw( 8 ) << std::setfill( '0' ) << x;
97  return ( ss.str() );
98  }
99  inline std::string hexString( uint16_t x )
100  {
101  std::ostringstream ss;
102  ss << "0x" << std::hex << std::setw( 4 ) << std::setfill( '0' ) << x;
103  return ( ss.str() );
104  }
105  inline std::string hexString( uint8_t x )
106  {
107  std::ostringstream ss;
108  ss << "0x" << std::hex << std::setw( 2 ) << std::setfill( '0' ) << static_cast<unsigned>( x );
109  return ( ss.str() );
110  }
111  inline std::string binaryString( uint64_t x )
112  {
113  std::ostringstream ss;
114  for ( int i = 63; i >= 0; i-- )
115  {
116  ss << ( ( x & ( 1LL << i ) ) ? 1 : 0 );
117  if ( i > 0 && i % 8 == 0 )
118  ss << " ";
119  }
120  return ( ss.str() );
121  }
122  inline std::string binaryString( uint32_t x )
123  {
124  std::ostringstream ss;
125  for ( int i = 31; i >= 0; i-- )
126  {
127  ss << ( ( x & ( 1LL << i ) ) ? 1 : 0 );
128  if ( i > 0 && i % 8 == 0 )
129  ss << " ";
130  }
131  return ( ss.str() );
132  }
133  inline std::string binaryString( uint16_t x )
134  {
135  std::ostringstream ss;
136  for ( int i = 15; i >= 0; i-- )
137  {
138  ss << ( ( x & ( 1LL << i ) ) ? 1 : 0 );
139  if ( i > 0 && i % 8 == 0 )
140  ss << " ";
141  }
142  return ( ss.str() );
143  }
144  inline std::string binaryString( uint8_t x )
145  {
146  std::ostringstream ss;
147  for ( int i = 7; i >= 0; i-- )
148  {
149  ss << ( ( x & ( 1LL << i ) ) ? 1 : 0 );
150  if ( i > 0 && i % 8 == 0 )
151  ss << " ";
152  }
153  return ( ss.str() );
154  }
155  inline std::string hexString( int64_t x )
156  {
157  return ( hexString( static_cast<uint64_t>( x ) ) );
158  }
159  inline std::string hexString( int32_t x )
160  {
161  return ( hexString( static_cast<uint32_t>( x ) ) );
162  }
163  inline std::string hexString( int16_t x )
164  {
165  return ( hexString( static_cast<uint16_t>( x ) ) );
166  }
167  inline std::string hexString( int8_t x )
168  {
169  return ( hexString( static_cast<uint8_t>( x ) ) );
170  }
171  inline std::string binaryString( int64_t x )
172  {
173  return ( binaryString( static_cast<uint64_t>( x ) ) );
174  }
175  inline std::string binaryString( int32_t x )
176  {
177  return ( binaryString( static_cast<uint32_t>( x ) ) );
178  }
179  inline std::string binaryString( int16_t x )
180  {
181  return ( binaryString( static_cast<uint16_t>( x ) ) );
182  }
183  inline std::string binaryString( int8_t x )
184  {
185  return ( binaryString( static_cast<uint8_t>( x ) ) );
186  }
187 
188  using ImageFileImplSharedPtr = std::shared_ptr<class ImageFileImpl>;
189  using ImageFileImplWeakPtr = std::weak_ptr<class ImageFileImpl>;
190  using NodeImplSharedPtr = std::shared_ptr<class NodeImpl>;
191  using NodeImplWeakPtr = std::weak_ptr<class NodeImpl>;
192 
193  using StringList = std::vector<std::string>;
194  using StringSet = std::set<std::string>;
195 
197  std::string generateRandomGUID();
198 }
header file for the E57 API
std::string binaryString(uint64_t x)
Definition: Common.h:111
std::shared_ptr< class NodeImpl > NodeImplSharedPtr
Definition: Common.h:190
std::weak_ptr< class ImageFileImpl > ImageFileImplWeakPtr
Definition: Common.h:189
std::shared_ptr< class ImageFileImpl > ImageFileImplSharedPtr
Definition: Common.h:188
std::weak_ptr< class NodeImpl > NodeImplWeakPtr
Definition: Common.h:191
std::set< std::string > StringSet
Definition: Common.h:194
std::string generateRandomGUID()
generates a new random GUID
Definition: Common.cpp:11
std::string toString(T x)
Definition: Common.h:80
std::vector< std::string > StringList
Definition: Common.h:193
std::string space(size_t n)
Definition: Common.h:73
std::string hexString(uint64_t x)
Definition: Common.h:87