GCC Code Coverage Report


Directory: ./
File: lib/geogram/basic/common.cpp
Date: 2026-09-07 02:25:23
Exec Total Coverage
Lines: 60 66 90.9%
Functions: 4 5 80.0%
Branches: 35 76 46.1%

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 249 static std::optional<GeogramLibSingleton>& instance(int flags) {
79
2/4
✓ Branch 0 taken 249 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 249 times.
✗ Branch 4 not taken.
498 static std::optional<GeogramLibSingleton> instance(flags);
80 249 return instance;
81 }
82
83 249 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 249 times.
✗ Branch 1 not taken.
249 if (flags & GEOGRAM_INSTALL_LOCALE) {
93 249 setenv("LC_NUMERIC","POSIX",1);
94 }
95 #endif
96
97 #ifndef GEOGRAM_PSM
98 249 Environment* env = Environment::instance();
99
3/8
✓ Branch 2 taken 249 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 249 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 249 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
498 env->set_value("version", GEOGRAM_VERSION);
100
3/8
✓ Branch 2 taken 249 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 249 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 249 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
498 env->set_value("release_date", VORPALINE_BUILD_DATE);
101
3/8
✓ Branch 2 taken 249 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 249 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 249 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
498 env->set_value("SVN revision", VORPALINE_SVN_REVISION);
102 #endif
103 249 FileSystem::initialize();
104 249 Logger::initialize();
105 249 Process::initialize(flags);
106 249 Progress::initialize();
107 249 CmdLine::initialize();
108 249 Stopwatch::initialize();
109 249 PCK::initialize();
110 249 Delaunay::initialize();
111
112 #ifndef GEOGRAM_PSM
113
1/2
✓ Branch 0 taken 249 times.
✗ Branch 1 not taken.
249 if (flags & GEOGRAM_INSTALL_BIBLIO) {
114 249 Biblio::initialize();
115 }
116 #endif
117
118 #ifndef GEOGRAM_PSM
119 249 mesh_io_initialize();
120 #endif
121
122 // Clear lastest system error
123
1/2
✓ Branch 0 taken 249 times.
✗ Branch 1 not taken.
249 if (flags & GEOGRAM_INSTALL_ERRNO) {
124 249 errno = 0;
125 }
126
127 #ifndef GEOGRAM_PSM
128 // Register attribute types that can be saved into files.
129
1/2
✓ Branch 2 taken 249 times.
✗ Branch 3 not taken.
249 geo_register_attribute_type<bool,Numeric::uint8>("bool");
130
1/2
✓ Branch 2 taken 249 times.
✗ Branch 3 not taken.
249 geo_register_attribute_type<char>("char");
131
1/2
✓ Branch 2 taken 249 times.
✗ Branch 3 not taken.
249 geo_register_attribute_type<unsigned char>("unsigned char");
132
1/2
✓ Branch 2 taken 249 times.
✗ Branch 3 not taken.
249 geo_register_attribute_type<int>("int");
133
1/2
✓ Branch 2 taken 249 times.
✗ Branch 3 not taken.
249 geo_register_attribute_type<unsigned int>("unsigned int");
134
1/2
✓ Branch 2 taken 249 times.
✗ Branch 3 not taken.
249 geo_register_attribute_type<index_t>("index_t");
135
1/2
✓ Branch 2 taken 249 times.
✗ Branch 3 not taken.
249 geo_register_attribute_type<signed_index_t>("signed_index_t");
136
1/2
✓ Branch 2 taken 249 times.
✗ Branch 3 not taken.
249 geo_register_attribute_type<float>("float");
137
1/2
✓ Branch 2 taken 249 times.
✗ Branch 3 not taken.
249 geo_register_attribute_type<double>("double");
138
139
1/2
✓ Branch 2 taken 249 times.
✗ Branch 3 not taken.
249 geo_register_attribute_type<vec2>("vec2");
140
1/2
✓ Branch 2 taken 249 times.
✗ Branch 3 not taken.
249 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 249 ImageLibrary::initialize() ;
173
174
1/2
✓ Branch 2 taken 249 times.
✗ Branch 3 not taken.
249 geo_declare_image_serializer<ImageSerializerSTBReadWrite>("png");
175
1/2
✓ Branch 2 taken 249 times.
✗ Branch 3 not taken.
249 geo_declare_image_serializer<ImageSerializerSTBReadWrite>("jpg");
176
1/2
✓ Branch 2 taken 249 times.
✗ Branch 3 not taken.
249 geo_declare_image_serializer<ImageSerializerSTBReadWrite>("jpeg");
177
1/2
✓ Branch 2 taken 249 times.
✗ Branch 3 not taken.
249 geo_declare_image_serializer<ImageSerializerSTBReadWrite>("tga");
178
1/2
✓ Branch 2 taken 249 times.
✗ Branch 3 not taken.
249 geo_declare_image_serializer<ImageSerializerSTBReadWrite>("bmp");
179
180
1/2
✓ Branch 2 taken 249 times.
✗ Branch 3 not taken.
249 geo_declare_image_serializer<ImageSerializer_xpm>("xpm") ;
181
1/2
✓ Branch 2 taken 249 times.
✗ Branch 3 not taken.
249 geo_declare_image_serializer<ImageSerializer_pgm>("pgm") ;
182 #endif
183 249 }
184
185 249 ~GeogramLibSingleton() {
186
187 249 if(
188
2/4
✓ Branch 2 taken 249 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 249 times.
498 CmdLine::arg_is_declared("sys:stats") &&
189
1/2
✓ Branch 2 taken 249 times.
✗ Branch 3 not taken.
498 CmdLine::get_arg_bool("sys:stats")
190 ) {
191 Logger::div("System Statistics");
192 PCK::show_stats();
193 Process::show_stats();
194 }
195
196 249 PCK::terminate();
197
198 #ifndef GEOGRAM_PSM
199 249 ImageLibrary::terminate() ;
200 249 Biblio::terminate();
201 #endif
202
203 249 Progress::terminate();
204 249 Process::terminate();
205 249 CmdLine::terminate();
206 249 Logger::terminate();
207 249 FileSystem::terminate();
208 249 Environment::terminate();
209
210 249 }
211 };
212
213 }
214
215 249 void initialize(int flags) {
216 249 GeogramLibSingleton::instance(flags);
217 249 }
218
219 void terminate() {
220 GeogramLibSingleton::instance(GEOGRAM_INSTALL_NONE).reset();
221 }
222 }
223