mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-08 06:05:17 +00:00
Made all C++ files clang-formatted.
Also added missing generated files. Change-Id: Ifd22a643a08e3f2edfce92812ed57b87fc0e1875
This commit is contained in:
@@ -1,23 +1,23 @@
|
||||
/*
|
||||
* Copyright 2014 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
* Copyright 2014 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include "flatbuffers/code_generators.h"
|
||||
#include "flatbuffers/idl.h"
|
||||
#include "flatbuffers/util.h"
|
||||
#include <iostream>
|
||||
|
||||
namespace flatbuffers {
|
||||
|
||||
@@ -30,8 +30,7 @@ namespace jsons {
|
||||
|
||||
std::string GenNativeType(BaseType type) {
|
||||
switch (type) {
|
||||
case BASE_TYPE_BOOL:
|
||||
return "boolean";
|
||||
case BASE_TYPE_BOOL: return "boolean";
|
||||
case BASE_TYPE_CHAR:
|
||||
case BASE_TYPE_UCHAR:
|
||||
case BASE_TYPE_SHORT:
|
||||
@@ -41,16 +40,13 @@ std::string GenNativeType(BaseType type) {
|
||||
case BASE_TYPE_LONG:
|
||||
case BASE_TYPE_ULONG:
|
||||
case BASE_TYPE_FLOAT:
|
||||
case BASE_TYPE_DOUBLE:
|
||||
return "number";
|
||||
case BASE_TYPE_STRING:
|
||||
return "string";
|
||||
default:
|
||||
return "";
|
||||
case BASE_TYPE_DOUBLE: return "number";
|
||||
case BASE_TYPE_STRING: return "string";
|
||||
default: return "";
|
||||
}
|
||||
}
|
||||
|
||||
template <class T> std::string GenFullName(const T *enum_def) {
|
||||
template<class T> std::string GenFullName(const T *enum_def) {
|
||||
std::string full_name;
|
||||
const auto &name_spaces = enum_def->defined_namespace->components;
|
||||
for (auto ns = name_spaces.cbegin(); ns != name_spaces.cend(); ++ns) {
|
||||
@@ -60,7 +56,7 @@ template <class T> std::string GenFullName(const T *enum_def) {
|
||||
return full_name;
|
||||
}
|
||||
|
||||
template <class T> std::string GenTypeRef(const T *enum_def) {
|
||||
template<class T> std::string GenTypeRef(const T *enum_def) {
|
||||
return "\"$ref\" : \"#/definitions/" + GenFullName(enum_def) + "\"";
|
||||
}
|
||||
|
||||
@@ -93,11 +89,10 @@ std::string GenType(const Type &type) {
|
||||
const auto &union_types = type.enum_def->vals.vec;
|
||||
for (auto ut = union_types.cbegin(); ut < union_types.cend(); ++ut) {
|
||||
auto &union_type = *ut;
|
||||
if (union_type->union_type.base_type == BASE_TYPE_NONE) {
|
||||
continue;
|
||||
}
|
||||
if (union_type->union_type.base_type == BASE_TYPE_NONE) { continue; }
|
||||
if (union_type->union_type.base_type == BASE_TYPE_STRUCT) {
|
||||
union_type_string.append("{ " + GenTypeRef(union_type->union_type.struct_def) + " }");
|
||||
union_type_string.append(
|
||||
"{ " + GenTypeRef(union_type->union_type.struct_def) + " }");
|
||||
}
|
||||
if (union_type != *type.enum_def->vals.vec.rbegin()) {
|
||||
union_type_string.append(",");
|
||||
@@ -106,10 +101,8 @@ std::string GenType(const Type &type) {
|
||||
union_type_string.append("]");
|
||||
return union_type_string;
|
||||
}
|
||||
case BASE_TYPE_UTYPE:
|
||||
return GenTypeRef(type.enum_def);
|
||||
default:
|
||||
return GenType(GenNativeType(type.base_type));
|
||||
case BASE_TYPE_UTYPE: return GenTypeRef(type.enum_def);
|
||||
default: return GenType(GenNativeType(type.base_type));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,35 +123,29 @@ class JsonSchemaGenerator : public BaseGenerator {
|
||||
code_ += "{";
|
||||
code_ += " \"$schema\": \"http://json-schema.org/draft-04/schema#\",";
|
||||
code_ += " \"definitions\": {";
|
||||
for (auto e = parser_.enums_.vec.cbegin();
|
||||
e != parser_.enums_.vec.cend();
|
||||
for (auto e = parser_.enums_.vec.cbegin(); e != parser_.enums_.vec.cend();
|
||||
++e) {
|
||||
code_ += " \"" + GenFullName(*e) + "\" : {";
|
||||
code_ += " " + GenType("string") + ",";
|
||||
std::string enumdef(" \"enum\": [");
|
||||
for (auto enum_value = (*e)->vals.vec.begin();
|
||||
enum_value != (*e)->vals.vec.end();
|
||||
++enum_value) {
|
||||
for (auto enum_value = (*e)->vals.vec.begin();
|
||||
enum_value != (*e)->vals.vec.end(); ++enum_value) {
|
||||
enumdef.append("\"" + (*enum_value)->name + "\"");
|
||||
if (*enum_value != (*e)->vals.vec.back()) {
|
||||
enumdef.append(", ");
|
||||
}
|
||||
if (*enum_value != (*e)->vals.vec.back()) { enumdef.append(", "); }
|
||||
}
|
||||
enumdef.append("]");
|
||||
code_ += enumdef;
|
||||
code_ += " },"; // close type
|
||||
}
|
||||
for (auto s = parser_.structs_.vec.cbegin();
|
||||
s != parser_.structs_.vec.cend();
|
||||
++s) {
|
||||
for (auto s = parser_.structs_.vec.cbegin();
|
||||
s != parser_.structs_.vec.cend(); ++s) {
|
||||
const auto &structure = *s;
|
||||
code_ += " \"" + GenFullName(structure) + "\" : {";
|
||||
code_ += " " + GenType("object") + ",";
|
||||
std::string comment;
|
||||
const auto &comment_lines = structure->doc_comment;
|
||||
for (auto comment_line = comment_lines.cbegin();
|
||||
comment_line != comment_lines.cend();
|
||||
++comment_line) {
|
||||
comment_line != comment_lines.cend(); ++comment_line) {
|
||||
comment.append(*comment_line);
|
||||
}
|
||||
if (comment.size() > 0) {
|
||||
@@ -169,10 +156,9 @@ class JsonSchemaGenerator : public BaseGenerator {
|
||||
const auto &properties = structure->fields.vec;
|
||||
for (auto prop = properties.cbegin(); prop != properties.cend(); ++prop) {
|
||||
const auto &property = *prop;
|
||||
std::string typeLine(" \"" + property->name + "\" : { " + GenType(property->value.type) + " }");
|
||||
if (property != properties.back()) {
|
||||
typeLine.append(",");
|
||||
}
|
||||
std::string typeLine(" \"" + property->name + "\" : { " +
|
||||
GenType(property->value.type) + " }");
|
||||
if (property != properties.back()) { typeLine.append(","); }
|
||||
code_ += typeLine;
|
||||
}
|
||||
code_ += " },"; // close properties
|
||||
@@ -184,8 +170,7 @@ class JsonSchemaGenerator : public BaseGenerator {
|
||||
if (requiredProperties.size() > 0) {
|
||||
std::string required_string(" \"required\" : [");
|
||||
for (auto req_prop = requiredProperties.cbegin();
|
||||
req_prop != requiredProperties.cend();
|
||||
++req_prop) {
|
||||
req_prop != requiredProperties.cend(); ++req_prop) {
|
||||
required_string.append("\"" + (*req_prop)->name + "\"");
|
||||
if (*req_prop != requiredProperties.back()) {
|
||||
required_string.append(", ");
|
||||
@@ -196,9 +181,7 @@ class JsonSchemaGenerator : public BaseGenerator {
|
||||
}
|
||||
code_ += " \"additionalProperties\" : false";
|
||||
std::string closeType(" }");
|
||||
if (*s != parser_.structs_.vec.back()) {
|
||||
closeType.append(",");
|
||||
}
|
||||
if (*s != parser_.structs_.vec.back()) { closeType.append(","); }
|
||||
code_ += closeType; // close type
|
||||
}
|
||||
code_ += " },"; // close definitions
|
||||
|
||||
Reference in New Issue
Block a user