JSON Voorhees
Killer JSON for C++
Loading...
Searching...
No Matches
config.hpp
Go to the documentation of this file.
1/// \file jsonv/config.hpp
2///
3/// Copyright (c) 2014-2020 by Travis Gockel. All rights reserved.
4///
5/// This program is free software: you can redistribute it and/or modify it under the terms of the Apache License
6/// as published by the Apache Software Foundation, either version 2 of the License, or (at your option) any later
7/// version.
8///
9/// \author Travis Gockel (travis@gockelhut.com)
10#pragma once
11
12/// \addtogroup Configuration
13/// \{
14
15/// \def JSONV_USER_CONFIG
16/// A user-defined configuration file to be included before all other JSON Voorhees content.
17#ifdef JSONV_USER_CONFIG
18# include JSONV_USER_CONFIG
19#endif
20
21/// \def JSONV_VERSION_MAJOR
22/// The major version of JSON Voorhees these headers belong to.
23#define JSONV_VERSION_MAJOR 2
24
25/// \def JSONV_VERSION_MINOR
26/// The minor version of JSON Voorhees these headers belong to.
27#define JSONV_VERSION_MINOR 0
28
29/// \def JSONV_VERSION_PATCH
30/// The patch version of JSON Voorhees these headers belong to.
31#define JSONV_VERSION_PATCH 0
32
33/// \def JSONV_VERSION_PRERELEASE
34/// The pre-release of JSON Voorhees these headers belong to, as a string literal: `"rc.1"` for 2.0.0-rc.1 and `""`
35/// for a release. It is a SemVer pre-release written without the `-` which joins it to the version, and the build
36/// accepts only dot-separated letters and digits.
37///
38/// A pre-release has the same three numbers, and so the same \c JSONV_VERSION, as the release it leads up to: a check
39/// such as `#if JSONV_VERSION >= 2000000` holds for the release candidates of 2.0.0 as well as for 2.0.0 itself. The
40/// preprocessor cannot look inside a string, but `std::string_view(JSONV_VERSION_PRERELEASE).empty()` is a constant
41/// expression which is \c true for a release.
42#define JSONV_VERSION_PRERELEASE "rc.1"
43
44/// \def JSONV_VERSION
45/// The version of JSON Voorhees these headers belong to as a single number,
46/// `JSONV_VERSION_MAJOR * 1000000 + JSONV_VERSION_MINOR * 1000 + JSONV_VERSION_PATCH`, so a version check can be
47/// written as `#if JSONV_VERSION >= 2000000`. It does not carry \c JSONV_VERSION_PRERELEASE.
48#define JSONV_VERSION (JSONV_VERSION_MAJOR * 1000000 + JSONV_VERSION_MINOR * 1000 + JSONV_VERSION_PATCH)
49
50/// \def JSONV_DEBUG
51/// \brief Was JSON Voorhees compiled in debug mode?
52/// This value must be the same between when the SO was built and when you are compiling. In general, this is not useful
53/// outside of library maintainers.
54///
55/// \warning
56/// Keep in mind this value is \e always defined. Use `#if JSONV_DEBUG`, \e not `#ifdef JSONV_DEBUG`.
57#ifndef JSONV_DEBUG
58# define JSONV_DEBUG 0
59#endif
60
61/// \def JSONV_SO
62/// \brief Are you using shared objects (DLLs in Windows)?
63#ifndef JSONV_SO
64# define JSONV_SO 1
65#endif
66
67/// \def JSONV_COMPILING
68/// \brief Is JSON Voorhees currently compiling?
69/// You do not want to set this by hand. It is set by the build system when the library is compiled.
70#ifndef JSONV_COMPILING
71# ifdef jsonv_EXPORTS
72# define JSONV_COMPILING 1
73# else
74# define JSONV_COMPILING 0
75# endif
76#endif
77
78/// \def JSONV_EXPORT
79/// If using shared objects, this class or function should be exported.
80///
81/// \def JSONV_IMPORT
82/// If using shared objects, this class or function should be imported.
83///
84/// \def JSONV_HIDDEN
85/// This symbol is only visible within the same shared object in which the translation unit will end up. Symbols which
86/// are "hidden" will \e not be put into the global offset table, which means code can be more optimal when it involves
87/// hidden symbols at the cost that nothing outside of the SO can access it.
88#if JSONV_SO
89# if defined(__GNUC__)
90# define JSONV_EXPORT __attribute__((visibility("default")))
91# define JSONV_IMPORT
92# define JSONV_HIDDEN __attribute__((visibility("hidden")))
93# elif defined(_MSC_VER)
94# if defined(_LIB)
95# define JSONV_EXPORT
96# define JSONV_IMPORT
97# define JSONV_HIDDEN
98# else
99# define JSONV_EXPORT __declspec(dllexport)
100# define JSONV_IMPORT __declspec(dllimport)
101# define JSONV_HIDDEN
102# endif
103# else
104# error "Unknown shared object semantics for this compiler."
105# endif
106#else
107# define JSONV_EXPORT
108# define JSONV_IMPORT
109# define JSONV_HIDDEN
110#endif
111
112/// \def JSONV_PUBLIC
113/// \brief This function or class is part of the public API for JSON Voorhees.
114/// If you are including JsonVoorhees for another library, this will have import semantics (\c JSONV_IMPORT); if you are
115/// building JsonVoorhees, this will have export semantics (\c JSONV_EXPORT).
116///
117/// \def JSONV_LOCAL
118/// \brief This function or class is internal-use only.
119/// \see JSONV_HIDDEN
120#if JSONV_COMPILING
121# define JSONV_PUBLIC JSONV_EXPORT
122# define JSONV_LOCAL JSONV_HIDDEN
123#else
124# define JSONV_PUBLIC JSONV_IMPORT
125# define JSONV_LOCAL JSONV_HIDDEN
126#endif
127
128/// \def JSONV_UNUSED
129/// \brief Note that you know the variable is unused, but make the compiler stop complaining about it.
130#ifndef JSONV_UNUSED
131# define JSONV_UNUSED [[maybe_unused]]
132#endif
133
134/// \def JSONV_NODISCARD
135/// \brief Warn if the caller discards the result of this function.
136/// This decorates the side-effect-free parts of the API, where dropping the result means the call did nothing at all.
137///
138/// The guard checks \c JSONV_DOXYGEN as well as the usual \c ifndef because \c config/Doxyfile predefines this macro
139/// as empty to keep it out of the rendered signatures. That also hides this \c define from Doxygen, which then warns
140/// about documentation for a macro it never saw; re-entering the block for Doxygen alone keeps the two consistent. No
141/// compiler defines \c JSONV_DOXYGEN, so everywhere else this is exactly the \c ifndef its siblings use.
142#if defined(JSONV_DOXYGEN) || !defined(JSONV_NODISCARD)
143# define JSONV_NODISCARD [[nodiscard]]
144#endif
145
146/// \def JSONV_NO_RETURN
147/// \brief Mark that a given function will never return control to the caller, either by exiting or throwing an
148/// exception.
149#ifndef JSONV_NO_RETURN
150# define JSONV_NO_RETURN [[noreturn]]
151#endif
152
153/// \def JSONV_INTEGER_ALTERNATES_LIST
154/// \brief An item list of types to also consider as an integer.
155/// This mostly exists to help resolve the C-induced type ambiguity for the literal \c 0. It most prefers to be an
156/// \c int, but might also become a \c long or a pointer type.
157#ifndef JSONV_INTEGER_ALTERNATES_LIST
158# define JSONV_INTEGER_ALTERNATES_LIST(item) \
159 item(int) \
160 item(unsigned int) \
161 item(unsigned long) \
162 item(unsigned long long)
163#endif
164
165/// \}