Skip to content

Commit

Permalink
code + cmake updated
Browse files Browse the repository at this point in the history
it works fine
  • Loading branch information
hugoledoux committed Sep 13, 2017
1 parent 4f48e9e commit c029bb1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
4 changes: 3 additions & 1 deletion software/cityjson-valschema/c++11/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ cmake_minimum_required (VERSION 3.2)
project (cityjson-valschema)

set(CMAKE_CXX_COMPILER g++)
set(CMAKE_CXX_FLAGS "-Wall -std=c++11")
set(CMAKE_CXX_FLAGS "-Wall -std=c++11 -Wno-unknown-pragmas")

set(${PROJECT_NAME}_VERSION_MAJOR 1)
set(${PROJECT_NAME}_VERSION_MINOR 0)


include_directories(include)
set(SOURCES src/main.cpp)

add_library(json-schema-validator SHARED
include/json-schema-draft4.json.cpp
include/json-uri.cpp
include/jsoncpp.cpp
include/json-validator.cpp)

add_executable(${PROJECT_NAME} ${SOURCES} src/main.cpp)
Expand Down
32 changes: 21 additions & 11 deletions software/cityjson-valschema/c++11/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ __ ____ _| |___ ___| |__ ___ _ __ ___ __ _
*/

#include <json-schema.hpp>
#include "json/json.h"
#include <fstream>
#include <iostream>
#include <sstream>
Expand All @@ -32,6 +33,7 @@ using nlohmann::json_schema_draft4::json_validator;

static void loader(const json_uri &uri, json &schema);
bool is_valid_json_schema(json& j, json& jschema, std::stringstream& ss);
bool is_valid_duplicate_keys(const char* nameinput);
bool is_valid_citygml_attributes(json& j, json& jschema);
bool is_valid_metadata(json& j, json& jschema);
bool is_valid_semantics(json& j);
Expand All @@ -44,7 +46,7 @@ int main(int argc, char *argv[]) {
bool isValid = true;
bool woWarnings = true;
json j;
const char* nameinput = (argc > 1) ? argv[1] : "/Users/hugo/temp/example2.json";
const char* nameinput = (argc > 1) ? argv[1] : "../../../../example-datasets/dummy-values/example2.json";
std::ifstream input2(nameinput);
input2 >> j;
std::cout << "Input file: " << nameinput << std::endl;
Expand Down Expand Up @@ -74,10 +76,16 @@ int main(int argc, char *argv[]) {
}

std::stringstream ss;
//-- validate the schema
if ( (isValid == true) && (is_valid_json_schema(j, jschema, ss) == false) ){
std::cout << ss.str() << std::endl;
isValid = false;
}
//-- check for duplicate keys, which is impossible with schema and/or my parsing library
if ( (isValid == true) && (is_valid_duplicate_keys(nameinput) == false) ){
std::cout << "ERROR: Duplicate IDs (keys) for the City Objects." << std::endl;
isValid = false;
}
if (isValid == true) {
if (is_valid_building_parts(j) == false)
isValid = false;
Expand All @@ -93,16 +101,6 @@ int main(int argc, char *argv[]) {
woWarnings = false;
}

//-- unique keys for CO?
std::cout << "=====" << std::endl;
for (json::iterator coit = j["CityObjects"].begin(); coit != j["CityObjects"].end(); ++coit) {
std::cout << coit.key() << std::endl;
if (coit.key() == "2929")
std::cout << coit.value() << std::endl;
}
std::cout << "=====" << std::endl;


std::cout << std::endl;
if (isValid == true) {
std::cout << "File is VALID";
Expand All @@ -119,6 +117,18 @@ int main(int argc, char *argv[]) {
}


bool is_valid_duplicate_keys(const char* nameinput) {
Json::CharReaderBuilder builder;
builder["rejectDupKeys"] = true;
JSONCPP_STRING errs;
Json::Value j; // 'root' will contain the root value after parsing.
// const char* nameinput = "/Users/hugo/projects/cityjson-new/example-datasets/dummy-values/example3.json";
std::ifstream input(nameinput);
bool ok = parseFromStream(builder, input, &j, &errs);
return ok;
}


bool is_valid_building_pi_parent(json& j) {
bool isValid = true;
std::set<std::string> pis;
Expand Down

0 comments on commit c029bb1

Please sign in to comment.