couchbase 4.2.1 → 4.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/CMakeLists.txt +1 -0
  2. package/deps/couchbase-cxx-client/.gitmodules +3 -0
  3. package/deps/couchbase-cxx-client/.idea/misc.xml +1 -0
  4. package/deps/couchbase-cxx-client/.idea/vcs.xml +1 -0
  5. package/deps/couchbase-cxx-client/CMakeLists.txt +11 -1
  6. package/deps/couchbase-cxx-client/README.md +3 -3
  7. package/deps/couchbase-cxx-client/cmake/CompilerWarnings.cmake +4 -1
  8. package/deps/couchbase-cxx-client/cmake/VersionInfo.cmake +13 -1
  9. package/deps/couchbase-cxx-client/cmake/build_version.hxx.in +1 -0
  10. package/deps/couchbase-cxx-client/core/cluster.hxx +15 -5
  11. package/deps/couchbase-cxx-client/core/impl/build_deferred_query_indexes.cxx +17 -6
  12. package/deps/couchbase-cxx-client/core/impl/cluster.cxx +1 -1
  13. package/deps/couchbase-cxx-client/core/impl/collection_query_index_manager.cxx +93 -0
  14. package/deps/couchbase-cxx-client/core/impl/configuration_profiles_registry.cxx +11 -0
  15. package/deps/couchbase-cxx-client/core/impl/create_query_index.cxx +119 -0
  16. package/deps/couchbase-cxx-client/core/impl/drop_query_index.cxx +108 -0
  17. package/deps/couchbase-cxx-client/core/impl/get.cxx +1 -1
  18. package/deps/couchbase-cxx-client/core/impl/get_all_query_indexes.cxx +76 -0
  19. package/deps/couchbase-cxx-client/core/impl/query.cxx +5 -7
  20. package/deps/couchbase-cxx-client/core/impl/watch_query_indexes.cxx +168 -0
  21. package/deps/couchbase-cxx-client/core/io/mcbp_session.cxx +15 -1
  22. package/deps/couchbase-cxx-client/core/logger/configuration.hxx +3 -0
  23. package/deps/couchbase-cxx-client/core/logger/level.hxx +21 -0
  24. package/deps/couchbase-cxx-client/core/logger/logger.hxx +4 -6
  25. package/deps/couchbase-cxx-client/core/meta/CMakeLists.txt +4 -2
  26. package/deps/couchbase-cxx-client/core/meta/features.hxx +31 -0
  27. package/deps/couchbase-cxx-client/core/meta/version.cxx +67 -5
  28. package/deps/couchbase-cxx-client/core/meta/version.hxx +12 -1
  29. package/deps/couchbase-cxx-client/core/metrics/CMakeLists.txt +4 -1
  30. package/deps/couchbase-cxx-client/core/metrics/logging_meter.cxx +46 -5
  31. package/deps/couchbase-cxx-client/core/metrics/logging_meter.hxx +10 -26
  32. package/deps/couchbase-cxx-client/core/operations/document_get_projected.cxx +3 -2
  33. package/deps/couchbase-cxx-client/core/operations/document_query.cxx +10 -12
  34. package/deps/couchbase-cxx-client/core/operations/document_query.hxx +1 -3
  35. package/deps/couchbase-cxx-client/core/operations/management/query_index_build.cxx +8 -14
  36. package/deps/couchbase-cxx-client/core/operations/management/query_index_build.hxx +2 -1
  37. package/deps/couchbase-cxx-client/core/operations/management/query_index_build_deferred.hxx +15 -8
  38. package/deps/couchbase-cxx-client/core/operations/management/query_index_create.cxx +7 -14
  39. package/deps/couchbase-cxx-client/core/operations/management/query_index_create.hxx +2 -0
  40. package/deps/couchbase-cxx-client/core/operations/management/query_index_drop.cxx +11 -16
  41. package/deps/couchbase-cxx-client/core/operations/management/query_index_drop.hxx +2 -0
  42. package/deps/couchbase-cxx-client/core/operations/management/query_index_get_all.cxx +8 -12
  43. package/deps/couchbase-cxx-client/core/operations/management/query_index_get_all.hxx +4 -3
  44. package/deps/couchbase-cxx-client/core/operations/management/query_index_get_all_deferred.cxx +21 -12
  45. package/deps/couchbase-cxx-client/core/operations/management/query_index_get_all_deferred.hxx +3 -2
  46. package/deps/couchbase-cxx-client/core/origin.hxx +1 -1
  47. package/deps/couchbase-cxx-client/core/platform/uuid.cc +1 -2
  48. package/deps/couchbase-cxx-client/core/protocol/cmd_hello.hxx +5 -1
  49. package/deps/couchbase-cxx-client/core/query_context.hxx +79 -0
  50. package/deps/couchbase-cxx-client/core/tracing/CMakeLists.txt +3 -1
  51. package/deps/couchbase-cxx-client/core/tracing/threshold_logging_tracer.cxx +19 -4
  52. package/deps/couchbase-cxx-client/core/tracing/threshold_logging_tracer.hxx +2 -2
  53. package/deps/couchbase-cxx-client/core/transactions/async_attempt_context.hxx +10 -4
  54. package/deps/couchbase-cxx-client/core/transactions/atr_cleanup_entry.cxx +52 -63
  55. package/deps/couchbase-cxx-client/core/transactions/attempt_context.hxx +8 -3
  56. package/deps/couchbase-cxx-client/core/transactions/attempt_context_impl.cxx +163 -126
  57. package/deps/couchbase-cxx-client/core/transactions/attempt_context_impl.hxx +24 -37
  58. package/deps/couchbase-cxx-client/core/transactions/forward_compat.hxx +4 -4
  59. package/deps/couchbase-cxx-client/core/transactions/internal/atr_cleanup_entry.hxx +51 -13
  60. package/deps/couchbase-cxx-client/core/transactions/internal/client_record.hxx +26 -1
  61. package/deps/couchbase-cxx-client/core/transactions/internal/doc_record.hxx +21 -0
  62. package/deps/couchbase-cxx-client/core/transactions/internal/logging.hxx +40 -18
  63. package/deps/couchbase-cxx-client/core/transactions/internal/transaction_context.hxx +5 -0
  64. package/deps/couchbase-cxx-client/core/transactions/result.hxx +26 -0
  65. package/deps/couchbase-cxx-client/core/transactions/staged_mutation.cxx +48 -47
  66. package/deps/couchbase-cxx-client/core/transactions/staged_mutation.hxx +6 -6
  67. package/deps/couchbase-cxx-client/core/transactions/transaction_context.cxx +33 -19
  68. package/deps/couchbase-cxx-client/core/transactions/transaction_get_result.hxx +18 -2
  69. package/deps/couchbase-cxx-client/core/transactions/transaction_links.hxx +25 -2
  70. package/deps/couchbase-cxx-client/core/transactions/transactions.cxx +4 -4
  71. package/deps/couchbase-cxx-client/core/transactions/transactions_cleanup.cxx +49 -56
  72. package/deps/couchbase-cxx-client/core/transactions/waitable_op_list.hxx +7 -7
  73. package/deps/couchbase-cxx-client/core/transactions.hxx +0 -12
  74. package/deps/couchbase-cxx-client/core/utils/binary.hxx +1 -1
  75. package/deps/couchbase-cxx-client/core/utils/keyspace.hxx +55 -0
  76. package/deps/couchbase-cxx-client/couchbase/build_query_index_options.hxx +12 -45
  77. package/deps/couchbase-cxx-client/couchbase/cluster.hxx +1 -1
  78. package/deps/couchbase-cxx-client/couchbase/cluster_options.hxx +6 -7
  79. package/deps/couchbase-cxx-client/couchbase/collection.hxx +8 -0
  80. package/deps/couchbase-cxx-client/couchbase/collection_query_index_manager.hxx +218 -0
  81. package/deps/couchbase-cxx-client/couchbase/configuration_profiles_registry.hxx +3 -0
  82. package/deps/couchbase-cxx-client/couchbase/create_primary_query_index_options.hxx +166 -0
  83. package/deps/couchbase-cxx-client/couchbase/create_query_index_options.hxx +172 -0
  84. package/deps/couchbase-cxx-client/couchbase/drop_primary_query_index_options.hxx +129 -0
  85. package/deps/couchbase-cxx-client/couchbase/drop_query_index_options.hxx +116 -0
  86. package/deps/couchbase-cxx-client/couchbase/fmt/cas.hxx +1 -1
  87. package/deps/couchbase-cxx-client/couchbase/fmt/query_scan_consistency.hxx +46 -0
  88. package/deps/couchbase-cxx-client/couchbase/fmt/query_status.hxx +70 -0
  89. package/deps/couchbase-cxx-client/couchbase/fmt/tls_verify_mode.hxx +46 -0
  90. package/deps/couchbase-cxx-client/couchbase/get_all_query_indexes_options.hxx +100 -0
  91. package/deps/couchbase-cxx-client/{core → couchbase}/management/query_index.hxx +2 -2
  92. package/deps/couchbase-cxx-client/couchbase/metrics/meter.hxx +16 -0
  93. package/deps/couchbase-cxx-client/couchbase/query_index_manager.hxx +178 -6
  94. package/deps/couchbase-cxx-client/couchbase/query_options.hxx +1 -18
  95. package/deps/couchbase-cxx-client/couchbase/scope.hxx +5 -2
  96. package/deps/couchbase-cxx-client/couchbase/tracing/request_tracer.hxx +16 -0
  97. package/deps/couchbase-cxx-client/couchbase/transactions/async_attempt_context.hxx +11 -4
  98. package/deps/couchbase-cxx-client/couchbase/transactions/attempt_context.hxx +5 -3
  99. package/deps/couchbase-cxx-client/couchbase/transactions/transaction_keyspace.hxx +16 -0
  100. package/deps/couchbase-cxx-client/couchbase/transactions/transaction_query_options.hxx +0 -6
  101. package/deps/couchbase-cxx-client/couchbase/watch_query_indexes_options.hxx +115 -0
  102. package/deps/couchbase-cxx-client/examples/minimal.cxx +3 -1
  103. package/deps/couchbase-cxx-client/test/test_integration_crud.cxx +72 -0
  104. package/deps/couchbase-cxx-client/test/test_integration_management.cxx +727 -310
  105. package/deps/couchbase-cxx-client/test/test_integration_query.cxx +4 -8
  106. package/deps/couchbase-cxx-client/test/test_integration_transcoders.cxx +14 -0
  107. package/deps/couchbase-cxx-client/test/test_transaction_transaction_public_blocking_api.cxx +34 -19
  108. package/deps/couchbase-cxx-client/test/test_unit_transaction_logging.cxx +66 -22
  109. package/deps/couchbase-cxx-client/test/test_unit_utils.cxx +51 -0
  110. package/deps/couchbase-cxx-client/test/tools/tool_kv_loader.cxx +2 -2
  111. package/deps/couchbase-cxx-client/test/utils/integration_test_guard.cxx +2 -0
  112. package/deps/couchbase-cxx-client/test/utils/wait_until.cxx +4 -4
  113. package/deps/couchbase-cxx-client/third_party/docopt/.travis.yml +103 -0
  114. package/deps/couchbase-cxx-client/third_party/docopt/CMakeLists.txt +129 -0
  115. package/deps/couchbase-cxx-client/third_party/docopt/LICENSE-Boost-1.0 +23 -0
  116. package/deps/couchbase-cxx-client/third_party/docopt/LICENSE-MIT +23 -0
  117. package/deps/couchbase-cxx-client/third_party/docopt/README.rst +479 -0
  118. package/deps/couchbase-cxx-client/third_party/docopt/docopt-config.cmake +1 -0
  119. package/deps/couchbase-cxx-client/third_party/docopt/docopt.cpp +687 -0
  120. package/deps/couchbase-cxx-client/third_party/docopt/docopt.h +98 -0
  121. package/deps/couchbase-cxx-client/third_party/docopt/docopt.pc.in +9 -0
  122. package/deps/couchbase-cxx-client/third_party/docopt/docopt_private.h +676 -0
  123. package/deps/couchbase-cxx-client/third_party/docopt/docopt_util.h +122 -0
  124. package/deps/couchbase-cxx-client/third_party/docopt/docopt_value.h +341 -0
  125. package/deps/couchbase-cxx-client/third_party/docopt/examples/naval_fate.cpp +36 -0
  126. package/deps/couchbase-cxx-client/third_party/docopt/main.cpp +16 -0
  127. package/deps/couchbase-cxx-client/third_party/docopt/run_testcase.cpp +40 -0
  128. package/deps/couchbase-cxx-client/third_party/docopt/run_tests.py +72 -0
  129. package/deps/couchbase-cxx-client/third_party/docopt/testcases.docopt +957 -0
  130. package/deps/couchbase-cxx-client/tools/CMakeLists.txt +14 -0
  131. package/deps/couchbase-cxx-client/tools/cbc.cxx +65 -0
  132. package/deps/couchbase-cxx-client/tools/command.hxx +31 -0
  133. package/deps/couchbase-cxx-client/tools/command_registry.cxx +43 -0
  134. package/deps/couchbase-cxx-client/tools/command_registry.hxx +39 -0
  135. package/deps/couchbase-cxx-client/tools/get.cxx +267 -0
  136. package/deps/couchbase-cxx-client/tools/get.hxx +26 -0
  137. package/deps/couchbase-cxx-client/tools/query.cxx +441 -0
  138. package/deps/couchbase-cxx-client/tools/query.hxx +26 -0
  139. package/deps/couchbase-cxx-client/tools/utils.cxx +418 -0
  140. package/deps/couchbase-cxx-client/tools/utils.hxx +150 -0
  141. package/deps/couchbase-cxx-client/tools/version.cxx +82 -0
  142. package/deps/couchbase-cxx-client/tools/version.hxx +26 -0
  143. package/dist/authenticators.d.ts +2 -2
  144. package/dist/authenticators.js +1 -2
  145. package/dist/binding.d.ts +32 -16
  146. package/dist/cluster.js +14 -7
  147. package/dist/collection.d.ts +6 -0
  148. package/dist/collection.js +8 -0
  149. package/dist/queryexecutor.js +1 -1
  150. package/dist/queryindexmanager.d.ts +100 -4
  151. package/dist/queryindexmanager.js +344 -118
  152. package/dist/transactions.js +0 -2
  153. package/package.json +1 -1
  154. package/src/connection.cpp +2 -0
  155. package/src/connection.hpp +1 -0
  156. package/src/connection_autogen.cpp +16 -0
  157. package/src/jstocbpp_autogen.hpp +93 -23
  158. package/src/jstocbpp_basic.hpp +24 -0
  159. package/src/jstocbpp_transactions.hpp +0 -8
  160. package/tools/gen-bindings-js.js +1 -0
  161. package/tools/gen-bindings-json.py +4 -2
  162. package/deps/couchbase-cxx-client/core/transactions/logging.cxx +0 -107
@@ -0,0 +1,122 @@
1
+ //
2
+ // docopt_util.h
3
+ // docopt
4
+ //
5
+ // Created by Jared Grubb on 2013-11-04.
6
+ // Copyright (c) 2013 Jared Grubb. All rights reserved.
7
+ //
8
+
9
+ #ifndef docopt_docopt_util_h
10
+ #define docopt_docopt_util_h
11
+
12
+ #if DOCTOPT_USE_BOOST_REGEX
13
+ #include <boost/regex.hpp>
14
+ namespace std {
15
+ using boost::regex;
16
+ using boost::sregex_token_iterator;
17
+ }
18
+ #else
19
+ #include <regex>
20
+ #endif
21
+
22
+ #if 0
23
+ #pragma mark -
24
+ #pragma mark General utility
25
+ #endif
26
+
27
+ namespace {
28
+ bool starts_with(std::string const& str, std::string const& prefix)
29
+ {
30
+ if (str.length() < prefix.length())
31
+ return false;
32
+ return std::equal(prefix.begin(), prefix.end(),
33
+ str.begin());
34
+ }
35
+
36
+ std::string trim(std::string&& str,
37
+ const std::string& whitespace = " \t\n")
38
+ {
39
+ const auto strEnd = str.find_last_not_of(whitespace);
40
+ if (strEnd==std::string::npos)
41
+ return {}; // no content
42
+ str.erase(strEnd+1);
43
+
44
+ const auto strBegin = str.find_first_not_of(whitespace);
45
+ str.erase(0, strBegin);
46
+
47
+ return std::move(str);
48
+ }
49
+
50
+ std::vector<std::string> split(std::string const& str, size_t pos = 0)
51
+ {
52
+ const char* const anySpace = " \t\r\n\v\f";
53
+
54
+ std::vector<std::string> ret;
55
+ while (pos != std::string::npos) {
56
+ auto start = str.find_first_not_of(anySpace, pos);
57
+ if (start == std::string::npos) break;
58
+
59
+ auto end = str.find_first_of(anySpace, start);
60
+ auto size = end==std::string::npos ? end : end-start;
61
+ ret.emplace_back(str.substr(start, size));
62
+
63
+ pos = end;
64
+ }
65
+
66
+ return ret;
67
+ }
68
+
69
+ std::tuple<std::string, std::string, std::string> partition(std::string str, std::string const& point)
70
+ {
71
+ std::tuple<std::string, std::string, std::string> ret;
72
+
73
+ auto i = str.find(point);
74
+
75
+ if (i == std::string::npos) {
76
+ // no match: string goes in 0th spot only
77
+ } else {
78
+ std::get<2>(ret) = str.substr(i + point.size());
79
+ std::get<1>(ret) = point;
80
+ str.resize(i);
81
+ }
82
+ std::get<0>(ret) = std::move(str);
83
+
84
+ return ret;
85
+ }
86
+
87
+ template <typename I>
88
+ std::string join(I iter, I end, std::string const& delim) {
89
+ if (iter==end)
90
+ return {};
91
+
92
+ std::string ret = *iter;
93
+ for(++iter; iter!=end; ++iter) {
94
+ ret.append(delim);
95
+ ret.append(*iter);
96
+ }
97
+ return ret;
98
+ }
99
+
100
+ std::vector<std::string> regex_split(std::string const& text, std::regex const& re)
101
+ {
102
+ std::vector<std::string> ret;
103
+ for (auto it = std::sregex_token_iterator(text.begin(), text.end(), re, -1);
104
+ it != std::sregex_token_iterator();
105
+ ++it) {
106
+ ret.emplace_back(*it);
107
+ }
108
+ return ret;
109
+ }
110
+ }
111
+
112
+ namespace docopt {
113
+ template <class T>
114
+ inline void hash_combine(std::size_t& seed, T const& v)
115
+ {
116
+ // stolen from boost::hash_combine
117
+ std::hash<T> hasher;
118
+ seed ^= hasher(v) + 0x9e3779b9 + (seed<<6) + (seed>>2);
119
+ }
120
+ }
121
+
122
+ #endif
@@ -0,0 +1,341 @@
1
+ //
2
+ // value.h
3
+ // docopt
4
+ //
5
+ // Created by Jared Grubb on 2013-10-14.
6
+ // Copyright (c) 2013 Jared Grubb. All rights reserved.
7
+ //
8
+
9
+ #ifndef docopt__value_h_
10
+ #define docopt__value_h_
11
+
12
+ #include <string>
13
+ #include <vector>
14
+ #include <functional> // std::hash
15
+ #include <iosfwd>
16
+ #include <stdexcept>
17
+
18
+ namespace docopt {
19
+
20
+ enum class Kind {
21
+ Empty,
22
+ Bool,
23
+ Long,
24
+ String,
25
+ StringList
26
+ };
27
+
28
+ /// A generic type to hold the various types that can be produced by docopt.
29
+ ///
30
+ /// This type can be one of: {bool, long, string, vector<string>}, or empty.
31
+ struct value {
32
+ /// An empty value
33
+ value() {}
34
+
35
+ value(std::string);
36
+ value(std::vector<std::string>);
37
+
38
+ explicit value(bool);
39
+ explicit value(long);
40
+ explicit value(int v) : value(static_cast<long>(v)) {}
41
+
42
+ ~value();
43
+ value(value const&);
44
+ value(value&&) noexcept;
45
+ value& operator=(value const&);
46
+ value& operator=(value&&) noexcept;
47
+
48
+ Kind kind() const { return kind_; }
49
+
50
+ // Test if this object has any contents at all
51
+ explicit operator bool() const { return kind_ != Kind::Empty; }
52
+
53
+ // Test the type contained by this value object
54
+ bool isBool() const { return kind_==Kind::Bool; }
55
+ bool isString() const { return kind_==Kind::String; }
56
+ bool isLong() const { return kind_==Kind::Long; }
57
+ bool isStringList() const { return kind_==Kind::StringList; }
58
+
59
+ // Throws std::invalid_argument if the type does not match
60
+ bool asBool() const;
61
+ long asLong() const;
62
+ std::string const& asString() const;
63
+ std::vector<std::string> const& asStringList() const;
64
+
65
+ size_t hash() const noexcept;
66
+
67
+ friend bool operator==(value const&, value const&);
68
+ friend bool operator!=(value const&, value const&);
69
+
70
+ private:
71
+ union Variant {
72
+ Variant() {}
73
+ ~Variant() { /* do nothing; will be destroyed by ~value */ }
74
+
75
+ bool boolValue;
76
+ long longValue;
77
+ std::string strValue;
78
+ std::vector<std::string> strList;
79
+ };
80
+
81
+ static const char* kindAsString(Kind kind) {
82
+ switch (kind) {
83
+ case Kind::Empty: return "empty";
84
+ case Kind::Bool: return "bool";
85
+ case Kind::Long: return "long";
86
+ case Kind::String: return "string";
87
+ case Kind::StringList: return "string-list";
88
+ }
89
+ return "unknown";
90
+ }
91
+
92
+ void throwIfNotKind(Kind expected) const {
93
+ if (kind_ == expected)
94
+ return;
95
+
96
+ std::string error = "Illegal cast to ";
97
+ error += kindAsString(expected);
98
+ error += "; type is actually ";
99
+ error += kindAsString(kind_);
100
+ throw std::runtime_error(std::move(error));
101
+ }
102
+
103
+ Kind kind_ = Kind::Empty;
104
+ Variant variant_ {};
105
+ };
106
+
107
+ /// Write out the contents to the ostream
108
+ DOCOPT_API std::ostream& operator<<(std::ostream&, value const&);
109
+ }
110
+
111
+ namespace std {
112
+ template <>
113
+ struct hash<docopt::value> {
114
+ size_t operator()(docopt::value const& val) const noexcept {
115
+ return val.hash();
116
+ }
117
+ };
118
+ }
119
+
120
+ namespace docopt {
121
+ inline
122
+ value::value(bool v)
123
+ : kind_(Kind::Bool)
124
+ {
125
+ variant_.boolValue = v;
126
+ }
127
+
128
+ inline
129
+ value::value(long v)
130
+ : kind_(Kind::Long)
131
+ {
132
+ variant_.longValue = v;
133
+ }
134
+
135
+ inline
136
+ value::value(std::string v)
137
+ : kind_(Kind::String)
138
+ {
139
+ new (&variant_.strValue) std::string(std::move(v));
140
+ }
141
+
142
+ inline
143
+ value::value(std::vector<std::string> v)
144
+ : kind_(Kind::StringList)
145
+ {
146
+ new (&variant_.strList) std::vector<std::string>(std::move(v));
147
+ }
148
+
149
+ inline
150
+ value::value(value const& other)
151
+ : kind_(other.kind_)
152
+ {
153
+ switch (kind_) {
154
+ case Kind::String:
155
+ new (&variant_.strValue) std::string(other.variant_.strValue);
156
+ break;
157
+
158
+ case Kind::StringList:
159
+ new (&variant_.strList) std::vector<std::string>(other.variant_.strList);
160
+ break;
161
+
162
+ case Kind::Bool:
163
+ variant_.boolValue = other.variant_.boolValue;
164
+ break;
165
+
166
+ case Kind::Long:
167
+ variant_.longValue = other.variant_.longValue;
168
+ break;
169
+
170
+ case Kind::Empty:
171
+ default:
172
+ break;
173
+ }
174
+ }
175
+
176
+ inline
177
+ value::value(value&& other) noexcept
178
+ : kind_(other.kind_)
179
+ {
180
+ switch (kind_) {
181
+ case Kind::String:
182
+ new (&variant_.strValue) std::string(std::move(other.variant_.strValue));
183
+ break;
184
+
185
+ case Kind::StringList:
186
+ new (&variant_.strList) std::vector<std::string>(std::move(other.variant_.strList));
187
+ break;
188
+
189
+ case Kind::Bool:
190
+ variant_.boolValue = other.variant_.boolValue;
191
+ break;
192
+
193
+ case Kind::Long:
194
+ variant_.longValue = other.variant_.longValue;
195
+ break;
196
+
197
+ case Kind::Empty:
198
+ default:
199
+ break;
200
+ }
201
+ }
202
+
203
+ inline
204
+ value::~value()
205
+ {
206
+ switch (kind_) {
207
+ case Kind::String:
208
+ variant_.strValue.~basic_string();
209
+ break;
210
+
211
+ case Kind::StringList:
212
+ variant_.strList.~vector();
213
+ break;
214
+
215
+ case Kind::Empty:
216
+ case Kind::Bool:
217
+ case Kind::Long:
218
+ default:
219
+ // trivial dtor
220
+ break;
221
+ }
222
+ }
223
+
224
+ inline
225
+ value& value::operator=(value const& other) {
226
+ // make a copy and move from it; way easier.
227
+ return *this = value{other};
228
+ }
229
+
230
+ inline
231
+ value& value::operator=(value&& other) noexcept {
232
+ // move of all the types involved is noexcept, so we dont have to worry about
233
+ // these two statements throwing, which gives us a consistency guarantee.
234
+ this->~value();
235
+ new (this) value(std::move(other));
236
+
237
+ return *this;
238
+ }
239
+
240
+ template <class T>
241
+ void hash_combine(std::size_t& seed, const T& v);
242
+
243
+ inline
244
+ size_t value::hash() const noexcept
245
+ {
246
+ switch (kind_) {
247
+ case Kind::String:
248
+ return std::hash<std::string>()(variant_.strValue);
249
+
250
+ case Kind::StringList: {
251
+ size_t seed = std::hash<size_t>()(variant_.strList.size());
252
+ for(auto const& str : variant_.strList) {
253
+ hash_combine(seed, str);
254
+ }
255
+ return seed;
256
+ }
257
+
258
+ case Kind::Bool:
259
+ return std::hash<bool>()(variant_.boolValue);
260
+
261
+ case Kind::Long:
262
+ return std::hash<long>()(variant_.longValue);
263
+
264
+ case Kind::Empty:
265
+ default:
266
+ return std::hash<void*>()(nullptr);
267
+ }
268
+ }
269
+
270
+ inline
271
+ bool value::asBool() const
272
+ {
273
+ throwIfNotKind(Kind::Bool);
274
+ return variant_.boolValue;
275
+ }
276
+
277
+ inline
278
+ long value::asLong() const
279
+ {
280
+ // Attempt to convert a string to a long
281
+ if (kind_ == Kind::String) {
282
+ const std::string& str = variant_.strValue;
283
+ std::size_t pos;
284
+ const long ret = stol(str, &pos); // Throws if it can't convert
285
+ if (pos != str.length()) {
286
+ // The string ended in non-digits.
287
+ throw std::runtime_error( str + " contains non-numeric characters.");
288
+ }
289
+ return ret;
290
+ }
291
+ throwIfNotKind(Kind::Long);
292
+ return variant_.longValue;
293
+ }
294
+
295
+ inline
296
+ std::string const& value::asString() const
297
+ {
298
+ throwIfNotKind(Kind::String);
299
+ return variant_.strValue;
300
+ }
301
+
302
+ inline
303
+ std::vector<std::string> const& value::asStringList() const
304
+ {
305
+ throwIfNotKind(Kind::StringList);
306
+ return variant_.strList;
307
+ }
308
+
309
+ inline
310
+ bool operator==(value const& v1, value const& v2)
311
+ {
312
+ if (v1.kind_ != v2.kind_)
313
+ return false;
314
+
315
+ switch (v1.kind_) {
316
+ case Kind::String:
317
+ return v1.variant_.strValue==v2.variant_.strValue;
318
+
319
+ case Kind::StringList:
320
+ return v1.variant_.strList==v2.variant_.strList;
321
+
322
+ case Kind::Bool:
323
+ return v1.variant_.boolValue==v2.variant_.boolValue;
324
+
325
+ case Kind::Long:
326
+ return v1.variant_.longValue==v2.variant_.longValue;
327
+
328
+ case Kind::Empty:
329
+ default:
330
+ return true;
331
+ }
332
+ }
333
+
334
+ inline
335
+ bool operator!=(value const& v1, value const& v2)
336
+ {
337
+ return !(v1 == v2);
338
+ }
339
+ }
340
+
341
+ #endif /* defined(docopt__value_h_) */
@@ -0,0 +1,36 @@
1
+ #include "docopt.h"
2
+
3
+ #include <iostream>
4
+
5
+ static const char USAGE[] =
6
+ R"(Naval Fate.
7
+
8
+ Usage:
9
+ naval_fate ship new <name>...
10
+ naval_fate ship <name> move <x> <y> [--speed=<kn>]
11
+ naval_fate ship shoot <x> <y>
12
+ naval_fate mine (set|remove) <x> <y> [--moored | --drifting]
13
+ naval_fate (-h | --help)
14
+ naval_fate --version
15
+
16
+ Options:
17
+ -h --help Show this screen.
18
+ --version Show version.
19
+ --speed=<kn> Speed in knots [default: 10].
20
+ --moored Moored (anchored) mine.
21
+ --drifting Drifting mine.
22
+ )";
23
+
24
+ int main(int argc, const char** argv)
25
+ {
26
+ std::map<std::string, docopt::value> args = docopt::docopt(USAGE,
27
+ { argv + 1, argv + argc },
28
+ true, // show help if requested
29
+ "Naval Fate 2.0"); // version string
30
+
31
+ for(auto const& arg : args) {
32
+ std::cout << arg.first << ": " << arg.second << std::endl;
33
+ }
34
+
35
+ return 0;
36
+ }
@@ -0,0 +1,16 @@
1
+ //
2
+ // main.cpp
3
+ // docopt
4
+ //
5
+ // Created by Jared Grubb on 2013-10-03.
6
+ // Copyright (c) 2013 Jared Grubb. All rights reserved.
7
+ //
8
+
9
+ #include "docopt.h"
10
+
11
+ int main(int argc, const char * argv[])
12
+ {
13
+
14
+ return 0;
15
+ }
16
+
@@ -0,0 +1,40 @@
1
+ //
2
+ // docopt_tests.cpp
3
+ // docopt
4
+ //
5
+ // Created by Jared Grubb on 2013-11-03.
6
+ // Copyright (c) 2013 Jared Grubb. All rights reserved.
7
+ //
8
+
9
+ #include "docopt.h"
10
+
11
+ #include <iostream>
12
+
13
+ int main(int argc, const char** argv)
14
+ {
15
+ if (argc < 2) {
16
+ std::cerr << "Usage: docopt_tests USAGE [arg]..." << std::endl;
17
+ exit(-5);
18
+ }
19
+
20
+ std::string usage = argv[1];
21
+ std::vector<std::string> args {argv+2, argv+argc};
22
+
23
+ auto result = docopt::docopt(usage, args);
24
+
25
+ // print it out in JSON form
26
+ std::cout << "{ ";
27
+ bool first = true;
28
+ for(auto const& arg : result) {
29
+ if (first) {
30
+ first = false;
31
+ } else {
32
+ std::cout << "," << std::endl;
33
+ }
34
+
35
+ std::cout << '"' << arg.first << '"' << ": " << arg.second;
36
+ }
37
+ std::cout << " }" << std::endl;
38
+
39
+ return 0;
40
+ }
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env python3
2
+
3
+ import re
4
+ import sys
5
+ import json
6
+ import subprocess
7
+
8
+ executable = "${TESTPROG}"
9
+
10
+ def parse_test(raw):
11
+ raw = re.compile('#.*$', re.M).sub('', raw).strip()
12
+ if raw.startswith('"""'):
13
+ raw = raw[3:]
14
+
15
+ for fixture in raw.split('r"""'):
16
+ name = ''
17
+ doc, _, body = fixture.partition('"""')
18
+ cases = []
19
+ for case in body.split('$')[1:]:
20
+ argv, _, expect = case.strip().partition('\n')
21
+ expect = json.loads(expect)
22
+ prog, _, argv = argv.strip().partition(' ')
23
+ cases.append((prog, argv, expect))
24
+
25
+ yield name, doc, cases
26
+
27
+ failures = 0
28
+ passes = 0
29
+
30
+ tests = open('${TESTCASES}','r').read()
31
+ for _, doc, cases in parse_test(tests):
32
+ if not cases: continue
33
+
34
+ for prog, argv, expect in cases:
35
+ args = [ x for x in argv.split() if x ]
36
+
37
+ expect_error = not isinstance(expect, dict)
38
+
39
+ error = None
40
+ out = None
41
+ try:
42
+ out = subprocess.check_output([executable, doc]+args, stderr=subprocess.STDOUT)
43
+ if expect_error:
44
+ error = " ** an error was expected but it appeared to succeed!"
45
+ else:
46
+ json_out = json.loads(out)
47
+ if expect != json_out:
48
+ error = " ** JSON does not match expected: %r" % expect
49
+ except subprocess.CalledProcessError as e:
50
+ if not expect_error:
51
+ error = "\n ** this should have succeeded! exit code = %s" % e.returncode
52
+
53
+ if not error:
54
+ passes += 1
55
+ continue
56
+
57
+ failures += 1
58
+
59
+ print("="*40)
60
+ print(doc)
61
+ print(':'*20)
62
+ print(prog, argv)
63
+ print('-'*20)
64
+ if out:
65
+ print(out)
66
+ print(error)
67
+
68
+ if failures:
69
+ print("%d failures" % failures)
70
+ sys.exit(1)
71
+ else:
72
+ print("PASS (%d)" % passes)