Skip to content

Commit

Permalink
changed behavior of aliases header
Browse files Browse the repository at this point in the history
  • Loading branch information
jsteemann committed Nov 19, 2015
1 parent d99a5e9 commit 56d3f5f
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 46 deletions.
3 changes: 2 additions & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ message(STATUS "Building examples: ${BuildExamples}")
# build examples
if(BuildExamples)
foreach (exampleName
exampleAttributeTranslation
exampleAliases
exampleArrayHandling
exampleArrayIterator
exampleAttributeTranslation
exampleBuilder
exampleBuilderFancy
exampleCustom
Expand Down
59 changes: 39 additions & 20 deletions examples/Embedding.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <velocypack/Builder.h>
#include <velocypack/Slice.h>
```

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:
Expand All @@ -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 <velocypack/vpack.h>
#include <velocypack/velocypack-aliases.h>
```

or, when using selective headers:

```cpp
#include <velocypack/Builder.h>
#include <velocypack/Slice.h>
#include <velocypack/velocypack-aliases.h>
```

100 changes: 75 additions & 25 deletions include/velocypack/velocypack-aliases.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 56d3f5f

Please sign in to comment.