Skip to content

Commit cca3fbe

Browse files
committed
Can now build and uses std optional instead of boost for output
1 parent f595ef1 commit cca3fbe

File tree

4 files changed

+48
-34
lines changed

4 files changed

+48
-34
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ set( SOURCE_FILES
6161

6262
add_library( json_to_cpp ${HEADER_FILES} ${SOURCE_FILES} )
6363
add_dependencies( json_to_cpp dependency_stub )
64-
target_link_libraries( json_to_cpp tz char_range ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} )
64+
target_link_libraries( json_to_cpp tz utf_range utf_string ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} )
6565

6666
add_executable( json_to_cpp_bin ${HEADER_FILES} ${SOURCE_FOLDER}/main.cpp )
6767
add_dependencies( json_to_cpp_bin dependency_stub )
68-
target_link_libraries( json_to_cpp_bin json_to_cpp parse_json char_range temp_file ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${CURL_LIBRARIES} )
68+
target_link_libraries( json_to_cpp_bin json_to_cpp parse_json utf_range temp_file ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${CURL_LIBRARIES} )
6969

7070
install( TARGETS json_to_cpp DESTINATION lib )
7171
install( TARGETS json_to_cpp_bin DESTINATION bin )

dependent_projects/dependencies.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ externalproject_add(
88
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/install
99
)
1010

11+
externalproject_add(
12+
parse_json_prj
13+
GIT_REPOSITORY "https://github.com/beached/parse_json.git"
14+
SOURCE_DIR "${CMAKE_BINARY_DIR}/dependencies/parse_json"
15+
GIT_TAG "master"
16+
INSTALL_DIR "${CMAKE_BINARY_DIR}/install"
17+
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/install
18+
)
19+
1120
externalproject_add(
1221
char_range_prj
1322
GIT_REPOSITORY "https://github.com/beached/char_range.git"

src/json_to_cpp.cpp

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
#include <daw/daw_string_view.h>
3434

3535
#include "json_to_cpp.h"
36+
#include <daw/json/daw_json_parser_v2.h>
37+
#include <daw/json/daw_json_parser.h>
38+
#include <daw/json/daw_json_value_t.h>
3639

3740
namespace daw {
3841
namespace json_to_cpp {
@@ -167,7 +170,7 @@ namespace daw {
167170
bool &is_optional( ) noexcept;
168171
bool const &is_optional( ) const noexcept;
169172

170-
std::type_index type( ) const;
173+
size_t type( ) const;
171174

172175
ti_value( )
173176
: value{nullptr} {}
@@ -217,12 +220,12 @@ namespace daw {
217220

218221
type_info_t( ) = default;
219222
type_info_t( type_info_t const & ) = default;
220-
type_info_t( type_info_t && ) = default;
223+
type_info_t( type_info_t && ) noexcept = default;
221224
type_info_t &operator=( type_info_t const & ) = default;
222-
type_info_t &operator=( type_info_t && ) = default;
225+
type_info_t &operator=( type_info_t && ) noexcept = default;
223226
virtual ~type_info_t( );
224227

225-
virtual std::type_index type( ) const = 0;
228+
virtual size_t type( ) const = 0;
226229
virtual std::string name( ) const = 0;
227230

228231
virtual type_info_t *clone( ) const = 0;
@@ -234,7 +237,7 @@ namespace daw {
234237
return value->name( );
235238
}
236239

237-
std::type_index ti_value::type( ) const {
240+
size_t ti_value::type( ) const {
238241
return value->type( );
239242
}
240243
std::map<std::string, ti_value> const &ti_value::children( ) const {
@@ -254,8 +257,9 @@ namespace daw {
254257
}
255258

256259
struct ti_null : public type_info_t {
257-
std::type_index type( ) const override {
258-
return std::type_index( typeid( daw::json::json_value_t::null_t ) );
260+
size_t type( ) const override {
261+
return daw::json::json_value_t::index_of<
262+
daw::json::json_value_t::null_t>( );
259263
}
260264

261265
std::string name( ) const override {
@@ -281,9 +285,9 @@ namespace daw {
281285
}
282286

283287
struct ti_integral : public type_info_t {
284-
std::type_index type( ) const override {
285-
return std::type_index(
286-
typeid( daw::json::json_value_t::integer_t ) );
288+
size_t type( ) const override {
289+
return daw::json::json_value_t::index_of<
290+
daw::json::json_value_t::integer_t>( );
287291
}
288292

289293
std::string name( ) const override {
@@ -296,8 +300,9 @@ namespace daw {
296300
};
297301

298302
struct ti_real : public type_info_t {
299-
std::type_index type( ) const override {
300-
return std::type_index( typeid( daw::json::json_value_t::real_t ) );
303+
size_t type( ) const override {
304+
return daw::json::json_value_t::index_of<
305+
daw::json::json_value_t::real_t>( );
301306
}
302307

303308
std::string name( ) const override {
@@ -310,9 +315,9 @@ namespace daw {
310315
};
311316

312317
struct ti_boolean : public type_info_t {
313-
std::type_index type( ) const override {
314-
return std::type_index(
315-
typeid( daw::json::json_value_t::boolean_t ) );
318+
size_t type( ) const override {
319+
return daw::json::json_value_t::index_of<
320+
daw::json::json_value_t::boolean_t>( );
316321
}
317322

318323
std::string name( ) const override {
@@ -325,9 +330,9 @@ namespace daw {
325330
};
326331

327332
struct ti_string : public type_info_t {
328-
std::type_index type( ) const override {
329-
return std::type_index(
330-
typeid( daw::json::json_value_t::string_t ) );
333+
size_t type( ) const override {
334+
return daw::json::json_value_t::index_of<
335+
daw::json::json_value_t::string_t>( );
331336
}
332337

333338
std::string name( ) const override {
@@ -342,9 +347,9 @@ namespace daw {
342347
struct ti_object : public type_info_t {
343348
std::string object_name;
344349

345-
std::type_index type( ) const override {
346-
return std::type_index(
347-
typeid( daw::json::json_value_t::object_t ) );
350+
size_t type( ) const override {
351+
return daw::json::json_value_t::index_of<
352+
daw::json::json_value_t::object_t>( );
348353
}
349354

350355
std::string name( ) const override {
@@ -360,9 +365,9 @@ namespace daw {
360365
};
361366

362367
struct ti_array : public type_info_t {
363-
std::type_index type( ) const override {
364-
return std::type_index(
365-
typeid( daw::json::json_value_t::array_t ) );
368+
size_t type( ) const override {
369+
return daw::json::json_value_t::index_of<
370+
daw::json::json_value_t::array_t>( );
366371
}
367372

368373
std::string name( ) const override {
@@ -416,7 +421,7 @@ namespace daw {
416421
using daw::json::json_value_t;
417422
types::ti_value result = b;
418423
static auto const null_type =
419-
std::type_index( typeid( daw::json::json_value_t::null_t ) );
424+
daw::json::json_value_t::index_of<daw::json::json_value_t::null_t>( );
420425
if( null_type == a.type( ) ) {
421426
result = b;
422427
result.is_optional( ) = true;
@@ -549,7 +554,7 @@ namespace daw {
549554
config.header_file( ) << "#pragma once\n\n";
550555
}
551556
if( obj_state.has_optionals )
552-
config.header_file( ) << "#include <boost/optional.hpp>\n";
557+
config.header_file( ) << "#include <optional>\n";
553558
if( obj_state.has_integrals )
554559
config.header_file( ) << "#include <cstdint>\n";
555560
if( obj_state.has_strings )
@@ -577,7 +582,7 @@ namespace daw {
577582
auto const &member_type = child.second.name( );
578583
config.header_file( ) << "\t";
579584
if( child.second.is_optional( ) ) {
580-
config.header_file( ) << "boost::optional<" << member_type << ">";
585+
config.header_file( ) << "std::optional<" << member_type << ">";
581586
} else {
582587
config.header_file( ) << member_type;
583588
}

src/main.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222

2323
#include <boost/algorithm/string/predicate.hpp>
2424
#include <boost/filesystem.hpp>
25-
#include <boost/optional.hpp>
2625
#include <boost/program_options.hpp>
2726
#include <cstdlib>
2827
#include <curl/curl.h>
2928
#include <fstream>
3029
#include <iostream>
30+
#include <optional>
3131
#include <memory>
3232
#include <string>
3333

@@ -36,7 +36,7 @@
3636
#include "json_to_cpp.h"
3737

3838
namespace {
39-
boost::optional<std::string> download( daw::string_view url, boost::string_view user_agent );
39+
std::optional<std::string> download( daw::string_view url, daw::string_view user_agent );
4040
bool is_url( daw::string_view path );
4141
} // namespace
4242

@@ -156,15 +156,15 @@ namespace {
156156
return totalBytes;
157157
}
158158

159-
boost::optional<std::string> download( daw::string_view url, boost::string_view user_agent ) {
159+
std::optional<std::string> download( daw::string_view url, daw::string_view user_agent ) {
160160
struct curl_slist *headers = nullptr;
161161
curl_slist_append( headers, "Accept: application/json" );
162162
curl_slist_append( headers, "Content-Type: application/json" );
163163
curl_slist_append( headers, "charsets: utf-8" );
164164

165165
CURL *curl = curl_easy_init( );
166166
if( !curl ) {
167-
return boost::none;
167+
return std::nullopt;
168168
}
169169
curl_easy_setopt( curl, CURLOPT_HTTPHEADER, headers );
170170
curl_easy_setopt( curl, CURLOPT_HTTPGET, 1 );
@@ -199,7 +199,7 @@ namespace {
199199

200200
if( httpCode != 200 ) {
201201
std::cerr << "Couldn't GET from " << url << '\n';
202-
return boost::none;
202+
return std::nullopt;
203203
}
204204

205205
return httpData;

0 commit comments

Comments
 (0)