cppcore
A small, portable C++ core library
Loading...
Searching...
No Matches
CPPCoreCommon.h
Go to the documentation of this file.
1
/*-----------------------------------------------------------------------------------------------
2
The MIT License (MIT)
3
4
Copyright (c) 2014-2025 Kim Kulling
5
6
Permission is hereby granted, free of charge, to any person obtaining a copy of
7
this software and associated documentation files (the "Software"), to deal in
8
the Software without restriction, including without limitation the rights to
9
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10
the Software, and to permit persons to whom the Software is furnished to do so,
11
subject to the following conditions:
12
13
The above copyright notice and this permission notice shall be included in all
14
copies or substantial portions of the Software.
15
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
-----------------------------------------------------------------------------------------------*/
23
#pragma once
24
25
#include <cstddef>
26
#include <cassert>
27
#include <cinttypes>
28
#include <string.h>
29
#include <stddef.h>
30
#include <stdio.h>
31
#include <stdarg.h>
32
#include <malloc.h>
33
34
namespace
cppcore
{
35
36
#if defined( _WIN32 ) || defined( _WIN64 )
37
# define CPPCORE_WINDOWS
38
# define _CRT_SECURE_NO_WARNINGS
39
#elif defined(__gnu_linux__)
40
# define CPPCORE_GNU_LINUX
41
#elif defined(__APPLE__) || defined(__MACH__)
42
# define CPPCORE_IOS
43
#else
44
# error "Unsupported operation system."
45
#endif
46
47
#ifdef CPPCORE_WINDOWS
48
# define CPPCORE_TAG_DLL_EXPORT __declspec(dllexport)
49
# define CPPCORE_TAG_DLL_IMPORT __declspec(dllimport )
50
# ifdef CPPCORE_BUILD
51
# define DLL_CPPCORE_EXPORT CPPCORE_TAG_DLL_EXPORT
52
# else
53
# define DLL_CPPCORE_EXPORT CPPCORE_TAG_DLL_IMPORT
54
# endif
55
// All disabled warnings for windows
56
# pragma warning( disable : 4251 )
// <class> needs to have dll-interface to be used by clients of class <class>
57
# define CPPCORE_STACK_ALLOC(size) ::alloca(size)
58
#else
59
# define DLL_CPPCORE_EXPORT __attribute__((visibility("default")))
60
# define CPPCORE_STACK_ALLOC(size) __builtin_alloca(size)
61
#endif
62
63
//-------------------------------------------------------------------------------------------------
68
//-------------------------------------------------------------------------------------------------
69
template
<
class
T>
70
void
ContainerClear
( T & ctr,
void
( *DeleterFunc )( T & ) =
nullptr
) {
71
if
( ctr.isEmpty() ) {
72
return
;
73
}
74
75
if
(
nullptr
== DeleterFunc ) {
76
for
(
size_t
i = 0; i < ctr.size(); ++i ) {
77
delete
ctr[ i ];
78
}
79
}
else
{
80
DeleterFunc( ctr );
81
}
82
ctr.clear();
83
}
84
85
//-------------------------------------------------------------------------------------------------
90
//-------------------------------------------------------------------------------------------------
91
#define CPPCORE_NONE_COPYING( name ) \
92
public: \
93
name( const name & ) = delete ;\
94
name( name && ) = delete; \
95
name &operator = ( const name & ) = delete;
96
97
//-------------------------------------------------------------------------------------------------
107
//-------------------------------------------------------------------------------------------------
108
#define CPPCORE_ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
109
110
using
HashId
= uint64_t;
111
112
}
// Namespace cppcore
cppcore
Definition
DateTime.h:28
cppcore::ContainerClear
void ContainerClear(T &ctr, void(*DeleterFunc)(T &)=nullptr)
Definition
CPPCoreCommon.h:70
cppcore::HashId
uint64_t HashId
Definition
CPPCoreCommon.h:110
include
cppcore
CPPCoreCommon.h
Generated by
1.15.0