diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index c60afe47..e5ce3f44 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -6,9 +6,10 @@ message(STATUS "Building examples: ${BuildExamples}") # build examples if(BuildExamples) foreach (exampleName - exampleAttributeTranslation + exampleAliases exampleArrayHandling exampleArrayIterator + exampleAttributeTranslation exampleBuilder exampleBuilderFancy exampleCustom diff --git a/examples/Embedding.md b/examples/Embedding.md index db5a5ceb..2ba145ac 100644 --- a/examples/Embedding.md +++ b/examples/Embedding.md @@ -168,13 +168,27 @@ allocated. Client-code must not access the `Buffer` object's memory after that. +Including the VPack headers +--------------------------- + +The easiest way of making the VPack library's classes available to a client +program is to include the header `velocypack/vpack.h`. This will import all +class declarations from the namespace `arangodb::velocypack`. It is also possible +to selectively include the headers for just the classes needed, e.g. + +```cpp +// only need Builder and Slice in the following code +// no need to include all VPack classes +#include +#include +``` + +Because only the actually required headers will be included, this variant may +save some compilation time. + Name clashes and class aliases ------------------------------ -The default way of making the VPack library's classes available to a client -program is to include the header `velocypack/vpack.h`. This will load the -classes definitions from namespace `arangodb::velocypack`. - To avoid full name qualification in client programs, it may be convenient to make all classes from this namespace available without extra qualification. The following line will do that: @@ -192,26 +206,31 @@ not an option, an alternative is to use the class name aliases that are defined in the header file `velocypack/velocypack-aliases.h`. This header file makes the most common VPack classes available under alternative -(hopefully unambiguous) class names with the prefix *VPack*: +(hopefully unambiguous) class names with the prefix *VPack*, for example: ```cpp using VPackArrayIterator = arangodb::velocypack::ArrayIterator; using VPackBuilder = arangodb::velocypack::Builder; using VPackCharBuffer = arangodb::velocypack::CharBuffer; using VPackCharBufferSink = arangodb::velocypack::CharBufferSink; -using VPackCollection = arangodb::velocypack::Collection; -using VPackDumper = arangodb::velocypack::Dumper; -using VPackException = arangodb::velocypack::Exception; -using VPackHexDump = arangodb::velocypack::HexDump; -using VPackObjectIterator = arangodb::velocypack::ObjectIterator; -using VPackOptions = arangodb::velocypack::Options; -using VPackParser = arangodb::velocypack::Parser; -using VPackSink = arangodb::velocypack::Sink; -using VPackSlice = arangodb::velocypack::Slice; -using VPackStringSink = arangodb::velocypack::StringSink; -using VPackStringStreamSink = arangodb::velocypack::StringStreamSink; -using VPackValue = arangodb::velocypack::Value; -using VPackValueLength = arangodb::velocypack::ValueLength; -using VPackValueType = arangodb::velocypack::ValueType; -using VPackVersion = arangodb::velocypack::Version; +... ``` + +Note that the `velocypack-aliases.h` header will only make those VPack classes +available under alternative names that have been included already. When using +this header, it should be included after the other VPack headers have been +included: + +```cpp +#include +#include +``` + +or, when using selective headers: + +```cpp +#include +#include +#include +``` + diff --git a/include/velocypack/velocypack-aliases.h b/include/velocypack/velocypack-aliases.h index 89fcc91a..f2aa9965 100644 --- a/include/velocypack/velocypack-aliases.h +++ b/include/velocypack/velocypack-aliases.h @@ -27,30 +27,80 @@ #ifndef VELOCYPACK_ALIASES_H #define VELOCYPACK_ALIASES_H 1 -#include "velocypack/vpack.h" - -using VPackArrayIterator = arangodb::velocypack::ArrayIterator; -using VPackAttributeExcludeHandler = arangodb::velocypack::AttributeExcludeHandler; -using VPackAttributeTranslator = arangodb::velocypack::AttributeTranslator; -using VPackBuilder = arangodb::velocypack::Builder; -using VPackCharBuffer = arangodb::velocypack::CharBuffer; -using VPackCharBufferSink = arangodb::velocypack::CharBufferSink; -using VPackCollection = arangodb::velocypack::Collection; -using VPackCustomTypeHandler = arangodb::velocypack::CustomTypeHandler; -using VPackDumper = arangodb::velocypack::Dumper; -using VPackException = arangodb::velocypack::Exception; -using VPackHexDump = arangodb::velocypack::HexDump; -using VPackObjectIterator = arangodb::velocypack::ObjectIterator; -using VPackOptions = arangodb::velocypack::Options; -using VPackParser = arangodb::velocypack::Parser; -using VPackSink = arangodb::velocypack::Sink; -using VPackSlice = arangodb::velocypack::Slice; -using VPackStringSink = arangodb::velocypack::StringSink; -using VPackStringStreamSink = arangodb::velocypack::StringStreamSink; -using VPackValue = arangodb::velocypack::Value; -using VPackValueLength = arangodb::velocypack::ValueLength; -using VPackValuePair = arangodb::velocypack::ValuePair; -using VPackValueType = arangodb::velocypack::ValueType; -using VPackVersion = arangodb::velocypack::Version; +#include "velocypack/velocypack-common.h" + +namespace { + + // unconditional typedefs + using VPackValueLength = arangodb::velocypack::ValueLength; + + // conditional typedefs, only uses when the respective headers are already included +#ifdef VELOCYPACK_ITERATOR_H + using VPackArrayIterator = arangodb::velocypack::ArrayIterator; + using VPackObjectIterator = arangodb::velocypack::ObjectIterator; +#endif + +#ifdef VELOCYPACK_BUILDER_H + using VPackBuilder = arangodb::velocypack::Builder; +#endif + +#ifdef VELOCYPACK_BUILDER_H + using VPackCharBuffer = arangodb::velocypack::CharBuffer; +#endif + +#ifdef VELOCYPACK_SINK_H + using VPackSink = arangodb::velocypack::Sink; + using VPackCharBufferSink = arangodb::velocypack::CharBufferSink; + using VPackStringSink = arangodb::velocypack::StringSink; + using VPackStringStreamSink = arangodb::velocypack::StringStreamSink; +#endif + +#ifdef VELOCYPACK_COLLECTION_H + using VPackCollection = arangodb::velocypack::Collection; +#endif + +#ifdef VELOCYPACK_ATTRIBUTETRANSLATOR_H + using VPackAttributeTranslator = arangodb::velocypack::AttributeTranslator; +#endif + +#ifdef VELOCYPACK_DUMPER_H + using VPackDumper = arangodb::velocypack::Dumper; +#endif + +#ifdef VELOCYPACK_EXCEPTION_H + using VPackException = arangodb::velocypack::Exception; +#endif + +#ifdef VELOCYPACK_HEXDUMP_H + using VPackHexDump = arangodb::velocypack::HexDump; +#endif + +#ifdef VELOCYPACK_OPTIONS_H + using VPackOptions = arangodb::velocypack::Options; + using VPackAttributeExcludeHandler = arangodb::velocypack::AttributeExcludeHandler; + using VPackCustomTypeHandler = arangodb::velocypack::CustomTypeHandler; +#endif + +#ifdef VELOCYPACK_PARSER_H + using VPackParser = arangodb::velocypack::Parser; +#endif + +#ifdef VELOCYPACK_SLICE_H + using VPackSlice = arangodb::velocypack::Slice; +#endif + +#ifdef VELOCYPACK_VALUE_H + using VPackValue = arangodb::velocypack::Value; + using VPackValuePair = arangodb::velocypack::ValuePair; +#endif + +#ifdef VELOCYPACK_VALUETYPE_H + using VPackValueType = arangodb::velocypack::ValueType; +#endif + +#ifdef VELOCYPACK_VERSION_H + using VPackVersion = arangodb::velocypack::Version; +#endif +} #endif