xref: /6.6.0/subjson/subdoc/util.h (revision 91577587)
1/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3*     Copyright 2015 Couchbase, Inc
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#ifndef SUBDOC_UTIL_H
18#define SUBDOC_UTIL_H
19
20#include "operations.h"
21#include <iostream>
22
23namespace Subdoc {
24
25/// This class contains various utilities, mainly useful for testing/debugging
26class Util {
27public:
28    /// Gets the actual match string
29    static std::string match_match(const Match&);
30
31    /// Gets the string of the match's parent container
32    static std::string match_parent(const Match&);
33
34    /// Gets the string of the match's key
35    static std::string match_key(const Match&);
36
37    /// Prints a representation of the various segments of the new document
38    static void dump_newdoc(const Result&, std::ostream& = std::cerr);
39
40    static const char *jsonerr(jsonsl_error_t err);
41
42    static void do_assert(const char *e,
43            const char *func, const char *file, int line);
44private:
45    Util();
46};
47} // namespace
48
49namespace std {
50ostream& operator<<(ostream&, const Subdoc::Error::Code&);
51inline ostream& operator<<(ostream& os, const Subdoc::Error& err) {
52    return os << err.code();
53}
54}
55
56#ifdef _MSC_VER
57#define SUBDOC__func__ __FUNCTION__
58#else
59#define SUBDOC__func__ __func__
60#endif
61
62#define SUBDOC_ASSERT(e) \
63    if (!(e)) { Util::do_assert(#e, SUBDOC__func__, __FILE__, __LINE__); }
64
65#endif /* SUBDOC_UTIL_H */
66