GCC Code Coverage Report


Directory: ./
File: lib/geogram/basic/common.cpp
Date: 2026-09-07 02:37:58
Exec Total Coverage
Lines: 60 66 90.9%
Functions: 4 5 80.0%
Branches: 58 118 49.2%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2000-2022 Inria
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * * Neither the name of the ALICE Project-Team nor the names of its
14 * contributors may be used to endorse or promote products derived from this
15 * software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 *
29 * Contact: Bruno Levy
30 *
31 * https://www.inria.fr/fr/bruno-levy
32 *
33 * Inria,
34 * Domaine de Voluceau,
35 * 78150 Le Chesnay - Rocquencourt
36 * FRANCE
37 *
38 */
39
40 #include <geogram/basic/common.h>
41 #include <geogram/basic/process.h>
42 #include <geogram/basic/logger.h>
43 #include <geogram/basic/progress.h>
44 #include <geogram/basic/command_line.h>
45 #include <geogram/basic/file_system.h>
46 #include <geogram/basic/stopwatch.h>
47 #include <geogram/numerics/multi_precision.h>
48 #include <geogram/numerics/predicates.h>
49 #include <geogram/delaunay/delaunay.h>
50 #include <geogram/mesh/mesh_io.h>
51 #include <geogram/version.h>
52 #include <geogram/bibliography/bibliography.h>
53
54 #include <geogram/image/image.h>
55 #include <geogram/image/image_library.h>
56 #include <geogram/image/image_serializer_stb.h>
57 #include <geogram/image/image_serializer_xpm.h>
58 #include <geogram/image/image_serializer_pgm.h>
59
60 #include <sstream>
61 #include <iomanip>
62 #include <optional>
63
64 #ifdef GEO_OS_EMSCRIPTEN
65 #include <emscripten.h>
66 #endif
67
68 namespace GEO {
69
70 namespace {
71
72 /**
73 * \brief A global object that manages initialization and
74 * termination of the Geogram library
75 */
76 struct GeogramLibSingleton {
77
78 251 static std::optional<GeogramLibSingleton>& instance(int flags) {
79
3/8
✓ Branch 0 taken 251 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 251 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 251 times.
✗ Branch 7 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
251 static std::optional<GeogramLibSingleton> instance(flags);
80 251 return instance;
81 }
82
83 251 GeogramLibSingleton(int flags) {
84
85 // When locale is set to non-us countries,
86 // this may cause some problems when reading
87 // floating-point numbers (some locale expect
88 // a decimal ',' instead of a '.').
89 // This restores the default behavior for
90 // reading floating-point numbers.
91 #ifdef GEO_OS_UNIX
92
1/2
✓ Branch 0 taken 251 times.
✗ Branch 1 not taken.
251 if (flags & GEOGRAM_INSTALL_LOCALE) {
93 251 setenv("LC_NUMERIC","POSIX",1);
94 }
95 #endif
96
97 #ifndef GEOGRAM_PSM
98 251 Environment* env = Environment::instance();
99
3/6
✓ Branch 1 taken 251 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 251 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 251 times.
✗ Branch 8 not taken.
1004 env->set_value("version", GEOGRAM_VERSION);
100
3/6
✓ Branch 1 taken 251 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 251 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 251 times.
✗ Branch 8 not taken.
1004 env->set_value("release_date", VORPALINE_BUILD_DATE);
101
3/6
✓ Branch 1 taken 251 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 251 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 251 times.
✗ Branch 8 not taken.
1004 env->set_value("SVN revision", VORPALINE_SVN_REVISION);
102 #endif
103 251 FileSystem::initialize();
104 251 Logger::initialize();
105 251 Process::initialize(flags);
106 251 Progress::initialize();
107 251 CmdLine::initialize();
108 251 Stopwatch::initialize();
109 251 PCK::initialize();
110 251 Delaunay::initialize();
111
112 #ifndef GEOGRAM_PSM
113
1/2
✓ Branch 0 taken 251 times.
✗ Branch 1 not taken.
251 if (flags & GEOGRAM_INSTALL_BIBLIO) {
114 251 Biblio::initialize();
115 }
116 #endif
117
118 #ifndef GEOGRAM_PSM
119 251 mesh_io_initialize();
120 #endif
121
122 // Clear lastest system error
123
1/2
✓ Branch 0 taken 251 times.
✗ Branch 1 not taken.
251 if (flags & GEOGRAM_INSTALL_ERRNO) {
124 251 errno = 0;
125 }
126
127 #ifndef GEOGRAM_PSM
128 // Register attribute types that can be saved into files.
129
2/4
✓ Branch 1 taken 251 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 251 times.
✗ Branch 5 not taken.
502 geo_register_attribute_type<bool,Numeric::uint8>("bool");
130
2/4
✓ Branch 1 taken 251 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 251 times.
✗ Branch 5 not taken.
502 geo_register_attribute_type<char>("char");
131
2/4
✓ Branch 1 taken 251 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 251 times.
✗ Branch 5 not taken.
502 geo_register_attribute_type<unsigned char>("unsigned char");
132
2/4
✓ Branch 1 taken 251 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 251 times.
✗ Branch 5 not taken.
502 geo_register_attribute_type<int>("int");
133
2/4
✓ Branch 1 taken 251 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 251 times.
✗ Branch 5 not taken.
502 geo_register_attribute_type<unsigned int>("unsigned int");
134
2/4
✓ Branch 1 taken 251 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 251 times.
✗ Branch 5 not taken.
502 geo_register_attribute_type<index_t>("index_t");
135
2/4
✓ Branch 1 taken 251 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 251 times.
✗ Branch 5 not taken.
502 geo_register_attribute_type<signed_index_t>("signed_index_t");
136
2/4
✓ Branch 1 taken 251 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 251 times.
✗ Branch 5 not taken.
502 geo_register_attribute_type<float>("float");
137
2/4
✓ Branch 1 taken 251 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 251 times.
✗ Branch 5 not taken.
502 geo_register_attribute_type<double>("double");
138
139
2/4
✓ Branch 1 taken 251 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 251 times.
✗ Branch 5 not taken.
502 geo_register_attribute_type<vec2>("vec2");
140
2/4
✓ Branch 1 taken 251 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 251 times.
✗ Branch 5 not taken.
251 geo_register_attribute_type<vec3>("vec3");
141 #endif
142
143 #ifdef GEO_OS_EMSCRIPTEN
144
145 // This mounts the local file system when an emscripten-compiled
146 // program runs in node.js.
147 // Current working directory is mounted in /working,
148 // and root directory is mounted in /root
149 //
150 // Skip this when NODERAWFS is enabled: the real
151 // filesystem is already mounted at '/', so
152 // FS.mkdir('/working') would try to create a
153 // directory at the real root and fail with EROFS
154 // (crashing worker pthreads).
155
156 EM_ASM(
157 if(
158 typeof NODERAWFS === 'undefined' &&
159 typeof module !== 'undefined' &&
160 this.module !== module
161 ) {
162 FS.mkdir('/working');
163 FS.mkdir('/root');
164 FS.mount(NODEFS, { root: '.' }, '/working');
165 FS.mount(NODEFS, { root: '/' }, '/root');
166 }
167 );
168
169 #endif
170
171 #ifndef GEOGRAM_PSM
172 251 ImageLibrary::initialize() ;
173
174
2/4
✓ Branch 1 taken 251 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 251 times.
✗ Branch 5 not taken.
502 geo_declare_image_serializer<ImageSerializerSTBReadWrite>("png");
175
2/4
✓ Branch 1 taken 251 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 251 times.
✗ Branch 5 not taken.
502 geo_declare_image_serializer<ImageSerializerSTBReadWrite>("jpg");
176
2/4
✓ Branch 1 taken 251 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 251 times.
✗ Branch 5 not taken.
502 geo_declare_image_serializer<ImageSerializerSTBReadWrite>("jpeg");
177
2/4
✓ Branch 1 taken 251 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 251 times.
✗ Branch 5 not taken.
502 geo_declare_image_serializer<ImageSerializerSTBReadWrite>("tga");
178
2/4
✓ Branch 1 taken 251 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 251 times.
✗ Branch 5 not taken.
502 geo_declare_image_serializer<ImageSerializerSTBReadWrite>("bmp");
179
180
2/4
✓ Branch 1 taken 251 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 251 times.
✗ Branch 5 not taken.
502 geo_declare_image_serializer<ImageSerializer_xpm>("xpm") ;
181
2/4
✓ Branch 1 taken 251 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 251 times.
✗ Branch 5 not taken.
251 geo_declare_image_serializer<ImageSerializer_pgm>("pgm") ;
182 #endif
183 251 }
184
185 251 ~GeogramLibSingleton() {
186
187 251 if(
188
3/6
✓ Branch 2 taken 251 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 251 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 251 times.
1255 CmdLine::arg_is_declared("sys:stats") &&
189
4/8
✗ Branch 2 not taken.
✓ Branch 3 taken 251 times.
✓ Branch 4 taken 251 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 251 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 251 times.
✗ Branch 10 not taken.
753 CmdLine::get_arg_bool("sys:stats")
190 ) {
191 Logger::div("System Statistics");
192 PCK::show_stats();
193 Process::show_stats();
194 }
195
196 251 PCK::terminate();
197
198 #ifndef GEOGRAM_PSM
199 251 ImageLibrary::terminate() ;
200 251 Biblio::terminate();
201 #endif
202
203 251 Progress::terminate();
204 251 Process::terminate();
205 251 CmdLine::terminate();
206 251 Logger::terminate();
207 251 FileSystem::terminate();
208 251 Environment::terminate();
209
210 251 }
211 };
212
213 }
214
215 251 void initialize(int flags) {
216 251 GeogramLibSingleton::instance(flags);
217 251 }
218
219 void terminate() {
220 GeogramLibSingleton::instance(GEOGRAM_INSTALL_NONE).reset();
221 }
222 }
223