Geophysical Inversion and Modelling Library v1.5.4
Loading...
Searching...
No Matches
gimli.h
1/******************************************************************************
2 * Copyright (C) 2006-2024 by the GIMLi development team *
3 * Carsten Rücker carsten@resistivity.net *
4 * *
5 * Licensed under the Apache License, Version 2.0 (the "License"); *
6 * you may not use this file except in compliance with the License. *
7 * You may obtain a copy of the License at *
8 * *
9 * http://www.apache.org/licenses/LICENSE-2.0 *
10 * *
11 * Unless required by applicable law or agreed to in writing, software *
12 * distributed under the License is distributed on an "AS IS" BASIS, *
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
14 * See the License for the specific language governing permissions and *
15 * limitations under the License. *
16 * *
17 ******************************************************************************/
18#ifndef _GIMLI_GIMLI__H
19#define _GIMLI_GIMLI__H
20
21#ifdef HAVE_CONFIG_CMAKE_H
22 #include <config.cmake.h>
23#else
24 #if defined(HAVE_CONFIG_H)
25 #include <config.h>
26 #define PACKAGE_AUTHORS "carsten@gimli.org, thomas@gimli.org, florian@gimli.org"
27 #endif
28#endif
29
30#ifndef TRUE
31 #define TRUE 1
32#endif
33
34#ifndef ON
35 #define ON 1
36#endif
37
38#if BOOST_THREAD_FOUND || defined(HAVE_BOOST_THREAD_HPP)
39 #define USE_BOOST_THREAD TRUE
40#endif
41
42#if BOOST_BIND_FOUND || defined(HAVE_BOOST_BIND_HPP)
43 #define USE_BOOST_BIND TRUE
44#endif
45
46#ifndef PACKAGE_NAME
47 #define PACKAGE_NAME "libgimli"
48 #define PACKAGE_VERSION "untagt-win"
49
50 #define PACKAGE_BUGREPORT "carsten@gimli.org"
51 #define PACKAGE_AUTHORS "carsten@gimli.org, thomas@gimli.org, florian@gimli.org"
52#endif // PACKAGE_NAME
53
54#ifdef _MSC_VER
55 #pragma warning(disable: 4251)
56#endif
57
58//#include <cassert>
59#include <iostream>
60#include <limits>
61#include <string>
62#include <vector>
63#include <map>
64#include <sstream>
65#include <cstdlib>
66#include <cerrno>
67#include <stdint.h>
68#include <complex>
69#include <algorithm>
70#include <functional>
71
72#include "platform.h"
73#include "exitcodes.h"
74
76namespace GIMLI{
77
78#ifndef __USE_MISC
79 typedef unsigned int uint;
80#endif
81
82typedef uint8_t uint8;
83typedef uint16_t uint16;
84typedef uint32_t uint32;
85typedef uint64_t uint64;
86
87typedef int8_t int8;
88typedef int16_t int16;
89typedef int32_t int32;
90typedef int64_t int64;
91
92#ifdef _WIN64
93 // for some magic reasons gccxml ignores the size_t = __int64 typedef under win64, so this helps let the python bindings through
94//#warning WIN64
95 typedef uint64 Index;
96 typedef int64 SIndex;
97#elif defined(_WIN32)
98//#warning WIN32
99 typedef uint32 Index;
100 typedef int32 SIndex;
101#elif defined(_MSC_VER)
102//#warning WINMSC
103 typedef unsigned __int32 Index;
104 typedef __int32 SIndex;
105#else
106// #warning DEFAULT
107 #include <sys/types.h>
108 typedef size_t Index;
109 // typedef signed long SIndex;
110 typedef ssize_t SIndex; // strange pygimli conversion into int on jenkins
111#endif
112
113#ifndef __ASSERT_FUNCTION
114 #if defined(_MSC_VER)
115 #define __ASSERT_FUNCTION __FUNCTION__
116 #else
117 #define __ASSERT_FUNCTION __PRETTY_FUNCTION__
118 #endif
119#endif
120
121
123DLLEXPORT std::string replace(const std::string & str,
124 const std::string & from,
125 const std::string & to);
126
127#ifndef SRC_DIR
128 #define SRC_DIR "./"
129#endif
130
131#ifdef _WIN64__
133 #define __FILENAME__ GIMLI::replace(__FILE__, SRC_DIR, ".")
134 // #define __FILENAME__ std::max<const char*>(__FILE__,\
135 // std::max(strrchr(__FILE__, '\\')+1, strrchr(__FILE__, '/')+1))
136#else
137 #define __FILENAME__ GIMLI::replace(__FILE__, SRC_DIR, ".")
138#endif
139
140
141#ifndef PYGIMLI_CAST // castxml complains on older gcc/clang
142inline std::string str(){ return "";}
143#endif
145template< typename T > inline std::string str(const T & v){
146 std::ostringstream os;
147 os << v;
148 return os.str();
149}
150enum LogType {Verbose, Info, Warning, Error, Debug, Critical};
151DLLEXPORT void log(LogType type, const std::string & msg);
152
153template<typename Value, typename... Values>
154std::string str(Value v, Values... vs){
155 std::ostringstream os;
156 using expander = int[];
157 os << v; // first
158 (void) expander{ 0, (os << " " << vs, void(), 0)... };
159 return os.str();
160}
161
162template<typename... Values>
163void log(LogType type, Values... vs){
164 return log(type, str(vs...));
165}
166
167// simple python like std out
168inline void print() {
169 std::cout << std::endl;
170}
171
172template<class Head>
173void print(std::ostream& s, Head&& head) {
174 s << std::forward<Head>(head) << std::endl;
175}
176
177template<class Head, class... Tail>
178void print(std::ostream& s, Head&& head, Tail&&... tail) {
179 s << std::forward<Head>(head) << " ";
180 print(s, std::forward<Tail>(tail)...);
181}
182
183template<class... Args>
184void print(Args&&... args) {
185 print(std::cout, std::forward<Args>(args)...);
186}
187
188#define WHERE GIMLI::str(__FILENAME__) + ":" + GIMLI::str(__LINE__) + "\t"
189#define WHERE_AM_I WHERE + "\t" + GIMLI::str(__ASSERT_FUNCTION) + " "
190#define TO_IMPL WHERE_AM_I + " not yet implemented\n " + GIMLI::versionStr() + "\nPlease send the messages above, the commandline and all necessary data to the author."
191
192#define __M std::cout << "*** " << WHERE << std::endl;
193#define __MS(str) std::cout << "*** " <<str << " " << WHERE << std::endl;
194// temporary
195#define __MSP(...) GIMLI::print("+++", WHERE, "\n", __VA_ARGS__, "\n---");
196#define __D if (debug()) std::cout << "Debug: " << WHERE << std::endl;
197#define __DS(str) if (debug()) std::cout << "Debug: " << str << " " << WHERE << std::endl;
198
199#define THROW_TO_IMPL throwToImplement(TO_IMPL);
200#define CERR_TO_IMPL std::cerr << TO_IMPL << std::endl;
201#define DEPRECATED std::cerr << WHERE_AM_I << " is deprecated " << std::endl;
202#define DEPR_STR(s) std::cerr << WHERE_AM_I << " is deprecated. Use: " << s " instead."<< std::endl;
203#define COUTMARKER std::cerr << WHERE_AM_I << std::endl;
204#define UNTESTED std::cerr << "WARNING!" << WHERE_AM_I << " " << "this function is untested" << std::endl;
205
206#define TOLERANCE 1e-12
207#define TOUCH_TOLERANCE 1e-12
208#define MAX_DOUBLE std::numeric_limits<double>::max()
209#define MAX_INT std::numeric_limits< int >::max()
210
211#define MESHBINSUFFIX ".bms"
212#define MATRIXBINSUFFIX ".bmat"
213#define MATRIXASCSUFFIX ".matrix"
214#define VECTORBINSUFFIX ".bvec"
215#define VECTORASCSUFFIX ".vector"
216#define NOT_DEFINED "notDefined"
217
218#define ASSERT_EQUAL_SIZE(m, n) if (m.size() != n.size()) \
219 throwLengthError(WHERE_AM_I + " " + str(m.size()) + " != " + str(n.size()));
220#define ASSERT_THIS_SIZE(n) if (n < 0 || n >= this->size()) \
221 throwLengthError(WHERE_AM_I + " " + str(this->size()) + " <= " + str(n));
222#define ASSERT_VEC_SIZE(vec, n) if (n != vec.size()) \
223 throwLengthError(WHERE_AM_I + " " + str(vec.size()) + " != " + str(n));
224#define ASSERT_SIZE(vec, n) if (n < 0 || n >= vec.size()) \
225 throwLengthError(WHERE_AM_I + " " + str(vec.size()) + " <= " + str(n));
226#define ASSERT_EQUAL(m, n) if (m != n) \
227 throwLengthError(WHERE_AM_I + " " + str(m) + " != " + str(n));
228#define ASSERT_RANGE(i, start, end) if (i < start || i >= end) \
229 throwRangeError(WHERE_AM_I, i, start, end);
230#define ASSERT_EMPTY(v) if (v.size()==0) \
231 throwLengthError(WHERE_AM_I + " array size is zero.");
232#define ASSERT_PTR(v) if (v == 0) \
233 throwError(WHERE_AM_I + " object not initialized.");
234
235static const int MARKER_BOUND_HOMOGEN_NEUMANN = -1;
236static const int MARKER_BOUND_MIXED = -2;
237static const int MARKER_BOUND_HOMOGEN_DIRICHLET = -3;
238static const int MARKER_BOUND_DIRICHLET = -4;
239static const int MARKER_CELL_PARAMETER = 2;
240static const int MARKER_NODE_SENSOR = -99;
241static const int MARKER_FIXEDVALUE_REGION = -1000000;
242
243static const uint8 MESH_BASEENTITY_RTTI = 00;
244static const uint8 MESH_MESHENTITY_RTTI = 01;
245static const uint8 MESH_NODE_RTTI = 10;
246static const uint8 MESH_BOUNDARY_RTTI = 20;
247static const uint8 MESH_BOUNDARY_NODE_RTTI = 21;
248static const uint8 MESH_EDGE_RTTI = 22;
249static const uint8 MESH_EDGE3_RTTI = 23;
250static const uint8 MESH_TRIANGLEFACE_RTTI = 24;
251static const uint8 MESH_TRIANGLEFACE6_RTTI = 25;
252static const uint8 MESH_QUADRANGLEFACE_RTTI = 26;
253static const uint8 MESH_QUADRANGLEFACE8_RTTI = 27;
254static const uint8 MESH_POLYGON_FACE_RTTI = 28;
255static const uint8 MESH_CELL_RTTI = 30;
256static const uint8 MESH_EDGE_CELL_RTTI = 31;
257static const uint8 MESH_EDGE3_CELL_RTTI = 32;
258static const uint8 MESH_TRIANGLE_RTTI = 33;
259static const uint8 MESH_TRIANGLE6_RTTI = 34;
260static const uint8 MESH_QUADRANGLE_RTTI = 35;
261static const uint8 MESH_QUADRANGLE8_RTTI = 36;
262static const uint8 MESH_QUADRANGLE9_RTTI = 37;
263static const uint8 MESH_TETRAHEDRON_RTTI = 41;
264static const uint8 MESH_TETRAHEDRON10_RTTI = 42;
265static const uint8 MESH_HEXAHEDRON_RTTI = 43;
266static const uint8 MESH_HEXAHEDRON20_RTTI = 44;
267static const uint8 MESH_TRIPRISM_RTTI = 45;
268static const uint8 MESH_TRIPRISM15_RTTI = 46;
269static const uint8 MESH_PYRAMID_RTTI = 47;
270static const uint8 MESH_PYRAMID13_RTTI = 48;
271
272static const uint8 MESH_SHAPE_NODE_RTTI = 210;
273static const uint8 MESH_SHAPE_EDGE_RTTI = 211;
274static const uint8 MESH_SHAPE_TRIANGLE_RTTI = 221;
275static const uint8 MESH_SHAPE_QUADRANGLE_RTTI = 222;
276static const uint8 MESH_SHAPE_POLYGON_FACE_RTTI = 223;
277static const uint8 MESH_SHAPE_TETRAHEDRON_RTTI = 231;
278static const uint8 MESH_SHAPE_HEXAHEDRON_RTTI = 232;
279static const uint8 MESH_SHAPE_TRIPRISM_RTTI = 233;
280static const uint8 MESH_SHAPE_PYRAMID_RTTI = 234;
281
282static const uint8 GIMLI_MATRIXBASE_RTTI = 0;
283static const uint8 GIMLI_MATRIX_RTTI = 1;
284static const uint8 GIMLI_SPARSE_MAP_MATRIX_RTTI = 2;
285static const uint8 GIMLI_SPARSE_CRS_MATRIX_RTTI = 3;
286static const uint8 GIMLI_BLOCKMATRIX_RTTI = 4;
287
289enum IOFormat{Ascii, Binary};
290
291//** start forward declaration
292class Boundary;
293class Cell;
294class DataContainer;
295class Line;
296class MatrixBase;
297class Mesh;
298class MeshEntity;
299class ModellingBase;
300class Node;
301class Plane;
302class Region;
303class RegionManager;
304class Shape;
305class Stopwatch;
306class Pos;
307class SolverWrapper;
308
309typedef Pos RVector3;
310typedef std::complex < double > Complex;
311
312template < class ValueType > class SparseMatrix;
313typedef SparseMatrix< int > ISparseMatrix;
314typedef SparseMatrix< double > RSparseMatrix;
315typedef SparseMatrix< Complex > CSparseMatrix;
316
317template< class ValueType, class IndexType > class SparseMapMatrix;
318typedef SparseMapMatrix< int, Index > ISparseMapMatrix;
319typedef SparseMapMatrix< double, Index > RSparseMapMatrix;
320typedef SparseMapMatrix< Complex, Index > CSparseMapMatrix;
321
322template < class ValueType > class Matrix;
323template < class ValueType > class BlockMatrix;
324template < class ValueType > class Matrix3;
325template < class ValueType > class Vector;
326
327typedef Vector < double > RVector;
328typedef Vector < Complex > CVector;
329typedef Vector < Pos > PosVector;
330typedef PosVector R3Vector;
331typedef Vector < bool > BVector;
332typedef Vector < SIndex > IVector;
333typedef Vector < Index > IndexArray;
334
335typedef std::vector < SIndex > SIndexArray;
336
337typedef Matrix < double > RMatrix;
338typedef Matrix3< double > RMatrix3;
339typedef Matrix < Complex > CMatrix;
340typedef BlockMatrix < double > RBlockMatrix;
341
342
343//#typedef Vector< unsigned char > BVector;
344
345// typedef std::vector < RVector > RMatrix;
346// typedef std::vector < CVector > CMatrix;
347
348template < class ValueType > class PolynomialFunction;
349typedef PolynomialFunction< double > RPolynomialFunction;
350
351template < class ValueType > class ElementMatrix;
352typedef ElementMatrix < double > RElementMatrix;
353
354template < class Vec > class Trans;
355
357DLLEXPORT void savePythonGIL(bool s);
358DLLEXPORT bool pythonGIL();
359
361DLLEXPORT void setDebug(bool s);
362DLLEXPORT bool debug();
363
365DLLEXPORT void setDeepDebug(int level);
366DLLEXPORT int deepDebug();
367
370DLLEXPORT void setThreadCount(Index nThreads);
371DLLEXPORT Index threadCount();
372
373DLLEXPORT void setUseOMP(bool o);
374DLLEXPORT bool useOMP();
375
377DLLEXPORT void showSizes();
378
379class DLLEXPORT PythonGILSave {
380public:
381 PythonGILSave() : saved_(false) { save(); }
382 ~PythonGILSave() { restore(); }
383 void save() ;
384 void restore();
385private:
386 bool saved_;
387#ifdef PYGIMLI
388 PyThreadState *save_;
389#endif
390};
391
392#define ALLOW_PYTHON_THREADS PythonGILSave __pygil_t__;
393#define RESTORE_PYTHON_THREADS __pygil_t__.restore();
394#define SAVE_PYTHON_THREADS __pygil_t__.save();
395
396#ifndef PYTHON_FOUND
397 #ifndef Py_BEGIN_ALLOW_THREADS
398 #define Py_BEGIN_ALLOW_THREADS
399 #define Py_END_ALLOW_THREADS
400 #endif
401#else
402// #include <Python.h>
403#endif
404
405DLLEXPORT std::string versionStr();
406
407DLLEXPORT std::string authors();
408
409template < class T, class U > T min(const T & a, const U & b){ return std::min(a, T(b)); }
410template < class T, class U > T max(const T & a, const U & b){ return std::max(a, T(b)); }
411
412DLLEXPORT int openFile(const std::string & fname, std::fstream * file,
413 std::ios_base::openmode farg, bool terminate);
414
415inline int openInFileTerm(const std::string & fname, std::fstream * file){
416 return openFile(fname, file, std::ios::in, true);
417}
418inline int openInFile(const std::string & fname, std::fstream * file,
419 bool terminate=true){
420 return openFile(fname, file, std::ios::in, terminate);
421}
422inline int openOutFile(const std::string & fname, std::fstream * file,
423 bool terminate=true){
424 return openFile(fname, file, std::ios::out, terminate);
425}
426
427DLLEXPORT bool fileExist(const std::string & filename);
428DLLEXPORT uint countColumnsInFile(const std::string & fname, uint & columnCount);
429DLLEXPORT uint countColumnsInFile(const std::string & fname);
430DLLEXPORT uint countRowsInFile(const std::string & fname);
431DLLEXPORT uint fileLength(std::fstream & file);
432DLLEXPORT std::vector < std::string > getRowSubstrings(std::fstream & file, char comment='#');
433
434inline std::vector < std::string > getRow(std::fstream & file, char comment='#'){
435 return getRowSubstrings(file, comment);
436}
437
438DLLEXPORT std::vector < std::string > getNonEmptyRow(std::fstream & file, char comment='#');
439DLLEXPORT std::vector < std::string > getCommentLine(std::fstream & file, char comment='#');
440
441DLLEXPORT std::vector < std::string > getSubstrings(const std::string & str);
442DLLEXPORT std::vector < std::string > split(const std::string & str, char delimiter=':');
443
444DLLEXPORT std::map < float, Complex > loadCFloatMap(const std::string & filename);
445DLLEXPORT std::map < float, float > loadFloatMap(const std::string & filename);
446DLLEXPORT std::map < int, int > loadIntMap(const std::string & filename);
447
448inline void convert(bool & var, char * opt) { var = true; }
449inline void convert(int & var, char * opt) { if (!opt) var ++; else var = atoi(opt); }
450inline void convert(uint & var, char * opt) { if (!opt) var ++; else var = atoi(opt); }
451inline void convert(Index & var, char * opt) { if (!opt) var ++; else var = atoi(opt); }
452inline void convert(float & var, char * opt) { if (!opt) var = 0.0f; else var = (float)atof(opt); }
453inline void convert(double & var, char * opt) { if (!opt) var = 0.0; else var = atof(opt); }
454inline void convert(std::string & var, char * opt) { if (!opt) var = ""; else var = opt ; }
455inline void convert(std::vector < std::string > & var, char * opt) { if (opt) var.push_back(opt); }
456
457inline std::string type(const bool & var) { return "bool"; }
458inline std::string type(const int32 & var) { return "int32"; }
459inline std::string type(const int64 & var) { return "int64"; }
460inline std::string type(const uint32 & var) { return "uint32"; }
461inline std::string type(const uint64 & var) { return "uint64"; }
462// inline std::string type(const Index & var) { return "Index"; }
463// inline std::string type(const SIndex & var) { return "SIndex"; }
464inline std::string type(const float & var) { return "float"; }
465inline std::string type(const double & var) { return "double"; }
466inline std::string type(const Complex & var) { return "complex"; }
467inline std::string type(const std::string & var) { return "string"; }
468inline std::string type(const std::vector < std::string > & var) { return "string"; }
469
470inline std::string type(const RVector & var) { return "RVector"; }
471inline std::string type(const RVector3 & var) { return "RVector3"; }
472inline std::string type(const R3Vector & var) { return "R3Vector"; }
473inline std::string type(const CVector & var) { return "CVector"; }
474inline std::string type(const RMatrix & var) { return "RMatrix"; }
475inline std::string type(const CMatrix & var) { return "CMatrix"; }
476
477inline int toInt(const std::string & str){ return std::atoi(str.c_str()); }
478inline float toFloat(const std::string & str){ return (float)std::atof(str.c_str()); }
479inline double toDouble(const std::string & str){ return std::strtod(str.c_str(), NULL); }
480
485template < typename ValueType > ValueType getEnvironment(const std::string & name,
486 ValueType def,
487 bool verbose=false){
488 ValueType var = def;
489
490 char * cVar = getenv(name.c_str());
491 if (cVar != NULL){
492 convert(var, cVar);
493 if (verbose) std::cout << "Found: export " << name << "=" << cVar << std::endl;
494 }
495 return var;
496}
497
500template < typename ValueType > void setEnvironment(const std::string & name,
501 ValueType val,
502 bool verbose=false){
503 int ret = setenv(name.c_str(), str(val).c_str(), 1);
504 switch(ret){
505 case EINVAL:
506 __MS(name << " " << val)
507 throwError("name is NULL, points to a string of length 0, or contains an '=' character.");
508 case ENOMEM:
509 __MS(name << " " << val)
510 throwError("name is NULL, Insufficient memory to add a new variable to the environment.");
511 }
512 if (verbose) std::cout << "set: export " << name << "=" << val << std::endl;
513}
514
516DLLEXPORT std::string replace(const std::string & str, const char from, const char to);
517
519DLLEXPORT std::string lower(const std::string & str);
520
521// template < typename T > inline void swapVal(T & a, T & m){
522// T tmp(a); a = m; m = tmp;
523// }
524
531struct DLLEXPORT deletePtr{
532 template < typename T > void operator()(T * p) { delete p; }
533};
534struct DLLEXPORT cerrPtr{
535 template < typename T > void operator() (const T * p) const { std::cerr << p << " " << std::endl; }
536};
537struct DLLEXPORT cerrPtrObject{
538 template < typename T > void operator() (const T * p) const { std::cerr << *p << " " << std::endl; }
539};
540struct DLLEXPORT coutPtr{
541 template < typename T > void operator() (const T * p) const { std::cout << p << " " << std::endl; }
542};
543struct DLLEXPORT coutPtrObject{
544 template < typename T > void operator() (const T * p) const { std::cout << *p << " " << std::endl; }
545};
546
547template < typename Set > inline void intersectionSet(Set & dest,
548 const Set & a,
549 const Set & b){
550 dest.clear();
551 set_intersection(a.begin(), a.end(), b.begin(), b.end(), std::inserter(dest, dest.begin()));
552}
553template < typename Set > inline void intersectionSet(Set & dest,
554 const Set & a,
555 const Set & b,
556 const Set & c){
557 dest.clear();
558 set_intersection(a.begin(), a.end(), b.begin(), b.end(),
559 std::inserter(dest, dest.begin()));
560 Set tmp(dest);
561 dest.clear();
562 set_intersection(tmp.begin(), tmp.end(), c.begin(), c.end(),
563 std::inserter(dest, dest.begin()));
564}
565
566template < typename Set > inline void intersectionSet(Set & dest,
567 const Set & a,
568 const Set & b,
569 const Set & c,
570 const Set & d){
571 dest.clear();
572 set_intersection(a.begin(), a.end(), b.begin(), b.end(),
573 std::inserter(dest, dest.begin()));
574 Set tmp(dest);
575 dest.clear();
576 set_intersection(tmp.begin(), tmp.end(), c.begin(), c.end(),
577 std::inserter(dest, dest.begin()));
578 tmp = dest;
579 dest.clear();
580 set_intersection(tmp.begin(), tmp.end(), d.begin(), d.end(),
581 std::inserter(dest, dest.begin()));
582}
583
584template < typename Set > inline void intersectionSet(Set & dest,
585 const std::vector < Set > & a){
586 if (a.size() > 1) {
587 intersectionSet(dest, a[0], a[1]);
588 for (size_t i = 2; i < a.size(); i ++){
589 Set tmp(dest);
590 dest.clear();
591 set_intersection(tmp.begin(), tmp.end(), a[i].begin(), a[i].end(),
592 std::inserter(dest, dest.begin()));
593 }
594 } else if (a.size() == 1){
595 dest = a[0];
596 } else {
597 dest.clear();
598 }
599}
600
601template < class T > class IncrementSequence {
602public:
603 IncrementSequence(T initialValue = 0) : value_(initialValue) { }
604 inline T operator() () { return value_++; }
605private:
606 T value_;
607};
608
610template < typename Classname > class DLLEXPORT Singleton {
611public:
612
613 virtual ~Singleton() {
614 #ifndef PYGIMLI_CAST
615 delete pInstance_; pInstance_ = NULL;
616 #endif
617 }
618
620 static Classname * pInstance() {
621 #ifndef PYGIMLI_CAST
622 return pInstance_ ? pInstance_ : (pInstance_ = new Classname());
623 #endif
624 return 0;
625 }
626
628 static Classname & instance() {
629 return *pInstance();
630 }
631
632protected:
635 Singleton(const Singleton &){__M};
636private:
638
640#ifndef PYGIMLI_CAST
641 static Classname * pInstance_;
642#endif
643};
644
645template < typename T > Index hash_(T v){
646 #ifndef PYGIMLI_CAST
647 return std::hash<T>()(v);
648 #endif
649 __M
650 return 0;
651}
654template <typename T>
655void hashCombine(Index & seed, const T& val){
656 seed ^= hash_(val) + 0x9e3779b9 + (seed<<6) + (seed>>2);
657}
658template <typename T, typename... Types>
659void hashCombine (Index & seed, const T & val, const Types&... args){
660 hashCombine(seed, val);
661 hashCombine(seed, args...);
662}
663inline void hashCombine (Index & seed){}
664template <typename... Types>
665Index hash(const Types&... args){
666 Index seed = 0;
667 hashCombine(seed, args...);
668 return seed;
669}
670template void hashCombine(Index & seed, const Index & hash);
671// template void hashCombine(Index & seed, const PosVector & val);
672// template void hashCombine(Index & seed, const Pos & val);
673// template void hashCombine(Index & seed, const DataContainer & val);
674
675} // namespace GIMLI
676
677#endif // _GIMLI_GIMLI__H
Definition gimli.h:610
Singleton()
Definition gimli.h:634
static Classname & instance()
Definition gimli.h:628
static Classname * pInstance()
Definition gimli.h:620
GIMLi main namespace for the Geophyiscal Inversion and Modelling Library.
Definition baseentity.h:24
void hashCombine(Index &seed, const T &val)
Definition gimli.h:655
ValueType getEnvironment(const std::string &name, ValueType def, bool verbose=false)
Definition gimli.h:485
void setEnvironment(const std::string &name, ValueType val, bool verbose=false)
Definition gimli.h:500
std::string lower(const std::string &str)
Definition gimli.cpp:305
void setDeepDebug(int level)
Definition gimli.cpp:131
std::string replace(const std::string &str, const std::string &from, const std::string &to)
Definition gimli.cpp:292
void showSizes()
Definition gimli.cpp:151
void setDebug(bool s)
Definition gimli.cpp:128
void setThreadCount(Index nThreads)
Definition gimli.cpp:73
IOFormat
Definition gimli.h:289
Definition gimli.h:537
Definition gimli.h:534
Definition gimli.h:543
Definition gimli.h:540
Definition gimli.h:531