Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SchemaDocument: Copy constructor #552

Closed
cviebig opened this issue Feb 19, 2016 · 2 comments
Closed

SchemaDocument: Copy constructor #552

cviebig opened this issue Feb 19, 2016 · 2 comments

Comments

@cviebig
Copy link

cviebig commented Feb 19, 2016

Hello @miloyip,

thank you for merging the Validator branch so fast.

I'm about to use it now and found a difference in behauvior of Document and SchemaDocument where I wonder if this is important. To me it seems that the copy constructor of SchemaDocument is implicitly deleted while Document maybe copied. Did I perceive this correctly? Alternatively I can of course use smart pointers, but just being curious, thus asking here :) So feel free to close it without much explanations please.

#include <rapidjson/document.h>
#include <rapidjson/schema.h>

::rapidjson::Document
load_json_from_file(
        const std::string& path_to_file) {
    std::string json = readFileContent(path_to_file);
    ::rapidjson::Document document;
    document.Parse(json.c_str());
    return document;
}

::rapidjson::SchemaDocument
load_schema_from_file(const std::string& path_to_file) {
    ::rapidjson::Document const& document =
        load_json_from_file(path_to_file);
    return ::rapidjson::SchemaDocument(document);
}

Stacktrace:

SchemaDocument const& schema = load_schema_from_file(schema_file);
Document const& document = load_json_from_file(path_to_file);

json_parser.cpp: In function ‘rapidjson::SchemaDocument load_schema_from_file(const string&)’:
json_parser.cpp:1397:52: error: use of deleted function ‘rapidjson::GenericSchemaDocument<rapidjson::GenericValue<rapidjson::UTF8<> > >::GenericSchemaDocument(const rapidjson::GenericSchemaDocument<rapidjson::GenericValue<rapidjson::UTF8<> > >&)’
         return ::rapidjson::SchemaDocument(document);
                                                    ^
In file included from json_validator.hpp:7:0,
                 from json_parser.cpp:42:
/usr/include/rapidjson/schema.h:1304:7: note: ‘rapidjson::GenericSchemaDocument<rapidjson::GenericValue<rapidjson::UTF8<> > >::GenericSchemaDocument(const rapidjson::GenericSchemaDocument<rapidjson::GenericValue<rapidjson::UTF8<> > >&)’ is implicitly deleted because the default definition would be ill-formed:
 class GenericSchemaDocument {
       ^
In file included from /usr/include/rapidjson/reader.h:23:0,
                 from /usr/include/rapidjson/document.h:20,
                 from json_parser.cpp:13:
/usr/include/rapidjson/internal/stack.h:212:5: error: ‘rapidjson::internal::Stack<Allocator>::Stack(const rapidjson::internal::Stack<Allocator>&) [with Allocator = rapidjson::CrtAllocator]’ is private
     Stack(const Stack&);
     ^
In file included from json_validator.hpp:7:0,
                 from json_parser.cpp:42:
/usr/include/rapidjson/schema.h:1304:7: error: within this context
 class GenericSchemaDocument {
       ^
In file included from /usr/include/rapidjson/reader.h:23:0,
                 from /usr/include/rapidjson/document.h:20,
                 from json_parser.cpp:13:
/usr/include/rapidjson/internal/stack.h:212:5: error: ‘rapidjson::internal::Stack<Allocator>::Stack(const rapidjson::internal::Stack<Allocator>&) [with Allocator = rapidjson::CrtAllocator]’ is private
     Stack(const Stack&);
     ^
In file included from json_validator.hpp:7:0,
                 from json_parser.cpp:42:
/usr/include/rapidjson/schema.h:1304:7: error: within this context
 class GenericSchemaDocument {
       ^
ninja: build stopped: subcommand failed.
@miloyip
Copy link
Collaborator

miloyip commented Feb 20, 2016

It is actually due to that Document supports move constructor in C++11.
I have added the move constructor for SchemaDocument in PR #554.

@cviebig
Copy link
Author

cviebig commented Feb 20, 2016

Cool, thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants