summaryrefslogtreecommitdiff
path: root/tools/intergen/cppgen/include
diff options
context:
space:
mode:
Diffstat (limited to 'tools/intergen/cppgen/include')
-rw-r--r--tools/intergen/cppgen/include/cppgen/comment.h61
-rw-r--r--tools/intergen/cppgen/include/cppgen/cpp_api_code_generator.h66
-rw-r--r--tools/intergen/cppgen/include/cppgen/cpp_class.h114
-rw-r--r--tools/intergen/cppgen/include/cppgen/cpp_file.h121
-rw-r--r--tools/intergen/cppgen/include/cppgen/cpp_function.h174
-rw-r--r--tools/intergen/cppgen/include/cppgen/cpp_interface_code_generator.h79
-rw-r--r--tools/intergen/cppgen/include/cppgen/declaration_generator.h109
-rw-r--r--tools/intergen/cppgen/include/cppgen/definition_generator.h72
-rw-r--r--tools/intergen/cppgen/include/cppgen/enum_from_json_value_function.h57
-rw-r--r--tools/intergen/cppgen/include/cppgen/enum_to_json_value_function.h54
-rw-r--r--tools/intergen/cppgen/include/cppgen/function_id_method.h77
-rw-r--r--tools/intergen/cppgen/include/cppgen/generator_preferences.h72
-rw-r--r--tools/intergen/cppgen/include/cppgen/handler_interface.h85
-rw-r--r--tools/intergen/cppgen/include/cppgen/is_valid_enum_function.h56
-rw-r--r--tools/intergen/cppgen/include/cppgen/literal_generator.h66
-rw-r--r--tools/intergen/cppgen/include/cppgen/message_factory_function.h76
-rw-r--r--tools/intergen/cppgen/include/cppgen/message_handle_with_method.h60
-rw-r--r--tools/intergen/cppgen/include/cppgen/message_interface.h82
-rw-r--r--tools/intergen/cppgen/include/cppgen/module_manager.h99
-rw-r--r--tools/intergen/cppgen/include/cppgen/namespace.h152
-rw-r--r--tools/intergen/cppgen/include/cppgen/naming_convention.h94
-rw-r--r--tools/intergen/cppgen/include/cppgen/struct_type_constructor.h71
-rw-r--r--tools/intergen/cppgen/include/cppgen/struct_type_dbus_serializer.h88
-rw-r--r--tools/intergen/cppgen/include/cppgen/struct_type_from_json_method.h73
-rw-r--r--tools/intergen/cppgen/include/cppgen/struct_type_is_initialized_method.h76
-rw-r--r--tools/intergen/cppgen/include/cppgen/struct_type_is_valid_method.h72
-rw-r--r--tools/intergen/cppgen/include/cppgen/struct_type_report_erros_method.h53
-rw-r--r--tools/intergen/cppgen/include/cppgen/type_name_code_generator.h153
28 files changed, 2412 insertions, 0 deletions
diff --git a/tools/intergen/cppgen/include/cppgen/comment.h b/tools/intergen/cppgen/include/cppgen/comment.h
new file mode 100644
index 0000000000..f4fdfb45ed
--- /dev/null
+++ b/tools/intergen/cppgen/include/cppgen/comment.h
@@ -0,0 +1,61 @@
+/**
+ * Copyright (c) 2014, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef COMMENT_H_
+#define COMMENT_H_
+
+#include <iosfwd>
+
+#include "utils/common_types.h"
+
+namespace codegen {
+
+// Class that represents C++ comment that can easily be output to
+// ostream,
+// comment text is wrapped with C++ comment marks (//) or /star automatically
+class Comment {
+ public:
+ // Create comment object from Description collected from xml
+ explicit Comment(const Description& description);
+ // Create single-line comment from string
+ explicit Comment(const std::string& text);
+ ~Comment();
+ private:
+ Description description_;
+ friend std::ostream& operator<<(std::ostream& os, const Comment& comment);
+};
+
+std::ostream& operator<<(std::ostream& os, const Comment& comment);
+
+} // namespace codegen
+
+#endif /* COMMENT_H_ */
diff --git a/tools/intergen/cppgen/include/cppgen/cpp_api_code_generator.h b/tools/intergen/cppgen/include/cppgen/cpp_api_code_generator.h
new file mode 100644
index 0000000000..c7ecf267b8
--- /dev/null
+++ b/tools/intergen/cppgen/include/cppgen/cpp_api_code_generator.h
@@ -0,0 +1,66 @@
+/**
+ * Copyright (c) 2014, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef CPP_API_CODE_GENERATOR_H_
+#define CPP_API_CODE_GENERATOR_H_
+
+#include <set>
+#include <string>
+
+#include "cppgen/generator_preferences.h"
+
+namespace codegen {
+class API;
+class Interface;
+
+/*
+ * Main C++ code generator class, takes parsed API object and produces
+ * header and implementation files for that code
+ */
+class CppApiCodeGenerator {
+ public:
+ CppApiCodeGenerator(const API* api);
+ ~CppApiCodeGenerator();
+ // Generate code for requested interfaces. Interface name id taken from
+ // Interface::name field converting it to a lower_case_identifier
+ std::set<std::string> Generate(const Preferences& preferences);
+ private:
+ // Produces code for single interface
+ bool GenerateInterface(const Interface* interface,
+ const TypePreferences& preferences);
+ private:
+ const API* api_;
+};
+
+} // namespace codegen
+
+#endif /* CPP_API_CODE_GENERATOR_H_ */
diff --git a/tools/intergen/cppgen/include/cppgen/cpp_class.h b/tools/intergen/cppgen/include/cppgen/cpp_class.h
new file mode 100644
index 0000000000..5f2ff4193c
--- /dev/null
+++ b/tools/intergen/cppgen/include/cppgen/cpp_class.h
@@ -0,0 +1,114 @@
+/* Copyright (c) 2014, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef CODEGEN_CPP_CLASS_H
+#define CODEGEN_CPP_CLASS_H
+
+#include <iosfwd>
+#include <string>
+#include <vector>
+
+#include "cppgen/cpp_function.h"
+
+namespace codegen {
+/*
+ * Class helper abstract class for C++ classes generation
+ * Must be inherited by a concrete class that provides
+ * class information by implementing pure virtual methods
+ */
+class CppClass {
+ public:
+ // Types
+ class Method;
+ class Superclass;
+ typedef std::vector<const Method*> MethodsList;
+ typedef std::vector<Superclass> SuperclassList;
+ // Member and inheritance access types specifier
+ enum AccessSpec {
+ kPublic, kProtected, kPrivate
+ };
+ public:
+ // Methods
+ // Creates class named |name|
+ CppClass(const std::string& name);
+ ~CppClass();
+ // Add superclass to classess parent's list
+ void Add(const Superclass& superclass);
+ // Output class declaration code to |os|
+ void Declare(std::ostream* os);
+ // Output class member's definition code to |os|
+ void Define(std::ostream* os);
+ // Class name
+ std::string name() const;
+protected:
+ // Methods
+ // To be defined by a concrete class, to provide
+ // Class member methods list
+ virtual const MethodsList& methods() = 0;
+private:
+ // Helper method that gives method list filtered by
+ // |access_spec|
+ MethodsList functions(AccessSpec access_spec);
+ // Fields
+ std::string name_;
+ SuperclassList superclasses_;
+};
+
+/*
+ * Helper class produces code for class method
+ */
+class CppClass::Method: public CppFunction {
+ public:
+ Method(const CppClass* cls, AccessSpec access, const std::string& name,
+ const std::string& return_type_name, int qualifiers = 0);
+ AccessSpec access_specifier() const;
+
+private:
+ AccessSpec access_specifier_;
+};
+
+/*
+ * Helper class that is used to specify class's parrents
+ */
+class CppClass::Superclass {
+public:
+ Superclass(const std::string& name, AccessSpec inheritance_type);
+ const std::string& name() const;
+ AccessSpec inheritance_type() const;
+
+private:
+ std::string name_;
+ AccessSpec inheritance_type_;
+};
+
+} // namespace codegen
+
+#endif // CODEGEN_CPP_CLASS_H
diff --git a/tools/intergen/cppgen/include/cppgen/cpp_file.h b/tools/intergen/cppgen/include/cppgen/cpp_file.h
new file mode 100644
index 0000000000..07857ccf4c
--- /dev/null
+++ b/tools/intergen/cppgen/include/cppgen/cpp_file.h
@@ -0,0 +1,121 @@
+/**
+ * Copyright (c) 2014, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef CPP_FILE_H_
+#define CPP_FILE_H_
+
+#include <iosfwd>
+#include <map>
+#include <set>
+#include <sstream>
+#include <string>
+
+#include "cppgen/namespace.h"
+#include "model/function.h"
+#include "utils/common_types.h"
+
+namespace codegen {
+class Type;
+
+/*
+ * Class representing C++ source file (generic) which contains C++ declarations
+ * and definitions placed in namespaces
+ * Can represent header or source file which basically differ in whether
+ * file's contents is wrapped with include guards
+ */
+class CppFile {
+ public:
+ // Types
+ class Header;
+ public:
+ // Methods
+ // Creates C++ file with name |file_name| that is part of module
+ // |module_name|.
+ // If |write_guards| is true, file contents is wrapped with include guards
+ // Module name is used to generate header guards and as a directory to
+ // write file into.
+ CppFile(const std::string& file_name, const std::string& module_name, bool write_guards);
+ ~CppFile();
+ const std::string& file_name() const;
+ // Adds header to file's include list
+ void Include(const Header& header);
+ // Automatically adds header where given type is defined
+ void IncludeType(const Type& type);
+ // Returns predefined namespaces for entities of different type
+ Namespace& global_namespace();
+ Namespace& types_ns();
+ Namespace& requests_ns();
+ Namespace& responses_ns();
+ Namespace& notifications_ns();
+ Namespace& NamespaceByMessageType(FunctionMessage::MessageType type);
+
+ // Generates code file named module_name/file_name and saves all namespaces
+ // into it.
+ void Write(std::ostream* os);
+
+ private:
+ Namespace& module_namespace();
+ // Methods
+ private:
+ bool write_guards_;
+ std::string file_name_;
+ std::string module_name_;
+ // Fields
+ std::stringstream contents_;
+ std::set<Header> headers_;
+ Namespace global_namespace_;
+};
+
+/*
+ * Class representing single header that is to be included into current one
+ */
+class CppFile::Header {
+ public:
+ // Methods
+
+ // Creates include directive with |name|.
+ // If |local| is true, name will be included in quotes, else
+ // it is included in <>
+ Header(const std::string& name, bool local);
+ bool is_local() const;
+ const std::string& name() const;
+ bool operator<(const Header& that) const;
+
+ private:
+ // Fields
+ std::string name_;
+ bool local_;
+};
+
+} // namespace codegen
+
+#endif /* CPP_FILE_H_ */
diff --git a/tools/intergen/cppgen/include/cppgen/cpp_function.h b/tools/intergen/cppgen/include/cppgen/cpp_function.h
new file mode 100644
index 0000000000..4aaecd75cc
--- /dev/null
+++ b/tools/intergen/cppgen/include/cppgen/cpp_function.h
@@ -0,0 +1,174 @@
+/**
+ * Copyright (c) 2014, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef CPP_FUNCTION_H_
+#define CPP_FUNCTION_H_
+
+#include <iosfwd>
+#include <string>
+#include <vector>
+
+namespace codegen {
+
+/*
+ * Class representing single generated C++ function or method
+ * Has methods to output that function declaration or definition to
+ * ostream
+ */
+class CppFunction {
+ public:
+ // Types and constants
+ struct Parameter;
+ struct OptionalParameter;
+ struct Initializer;
+ // C++ Function qualifiers
+ static const int kVirtual = 1 << 0;
+ static const int kStatic = 1 << 1;
+ static const int kExplicit = 1 << 2;
+ static const int kConst = 1 << 3;
+ static const int kVolatile = 1 << 4;
+ static const int kAbstract = 1 << 5;
+ public:
+ // Methods
+ // Creates a C++ function that belongs to |class_name|
+ // (should be empty for free functions), has a |name| and returns
+ // value of |return_type_name|. Might have combination of optional
+ // |qualifiers| (kVirtual | kConst, etc.)
+ CppFunction(const std::string& class_name, const std::string& name,
+ const std::string& return_type_name, int qualifiers = 0);
+ virtual ~CppFunction();
+ // Adds a (mandatory) parameter to a function, parameters are declared in the
+ // same order they were added
+ void Add(const Parameter& parameter);
+ // Adds an optional parameter. Optional parameters are declared
+ // after mandatory parameters in the order they were added
+ void Add(const OptionalParameter& parameter);
+ // Adds initializer statement, used by constructors
+ void Add(const Initializer& initializer);
+ // Outputs function declaration to ostream |os|, if
+ // |in_class| is true, declaration will have all the
+ // qualifiers present and class name omitted
+ // following C++ rules of method declaration
+ void Declare(std::ostream* os, bool in_class) const;
+ // Outputs function definition (signature and body) to ostream |os|.
+ // if |in_class| is true, declaration will have all the
+ // qualifiers present and class name omitted
+ // following C++ rules of method declaration
+ void Define(std::ostream* os, bool in_class) const;
+ // Returns true if generated function has at least one parameter that is not
+ // optional e.g. can not be called without parameters.
+ bool has_mandatory_parameters() const;
+ private:
+ // Outputs function prototype to |os|.
+ // if |in_class| is true, declaration will have all the
+ // qualifiers present and class name omitted
+ // following C++ rules of method declaration
+ // If |default_values| is true, output values for optional
+ // parameters (these should be written when function is declared).
+ void WriteFunctionPrototype(std::ostream* os, bool in_class,
+ bool default_values) const;
+ // Outputs constructor initializer list
+ void WriteInitializerList(std::ostream* os) const;
+ protected:
+ // A method to be defined by derived classes that outputs function code
+ virtual void DefineBody(std::ostream* os) const;
+ int qualifiers_;
+ std::string class_name_;
+ std::string name_;
+ std::string return_type_name_;
+ std::vector<Parameter> parameters_;
+ std::vector<OptionalParameter> optional_params_;
+ std::vector<Initializer> initializers_;
+};
+
+/*
+ * Represents single function parameter
+ */
+struct CppFunction::Parameter {
+ // Every parameter has name and type, which are passed as
+ // |name| and |type_name|
+ Parameter(const std::string& name, const std::string& type_name);
+ ~Parameter();
+ std::string name;
+ std::string type_name;
+};
+
+/*
+ * Represents single optional parameter function can accept
+ * it is different from usual parameter as it has default value
+ */
+struct CppFunction::OptionalParameter : CppFunction::Parameter {
+ // Every optional parameter has name and type, which are passed as
+ // |name| and |type_name|. Default initializer expression is passed as
+ // |default_value| parameter.
+ OptionalParameter(const std::string& name, const std::string& type_name,
+ const std::string& default_value);
+ ~OptionalParameter();
+ std::string default_value;
+};
+
+/*
+ * Represents initializer entry for constructor initializer list.
+ * Every entry consists of |field_name| to be initialized and it's
+ * |initializer| expression.
+ */
+struct CppFunction::Initializer {
+ Initializer(const std::string& field_name, const std::string& initializer);
+ ~Initializer();
+ std::string field_name;
+ std::string initializer;
+};
+
+/*
+ * Constructor is a specialized C++ function that only needs type_name
+ * to be defined. Parameters (if any) can be added later.
+ */
+class CppStructConstructor: public CppFunction {
+ public:
+ // Generates a constructor for type named |type_name|.
+ CppStructConstructor(const std::string& type_name);
+ ~CppStructConstructor();
+};
+
+/*
+ * Destructor is a specialized C++ function that only needs type_name
+ * to be defined.
+ */
+class CppStructDestructor: public CppFunction {
+ public:
+ CppStructDestructor(const std::string& type_name, bool abstract = false);
+ ~CppStructDestructor();
+};
+
+} // namespace codegen
+
+#endif /* CPP_FUNCTION_H_ */
diff --git a/tools/intergen/cppgen/include/cppgen/cpp_interface_code_generator.h b/tools/intergen/cppgen/include/cppgen/cpp_interface_code_generator.h
new file mode 100644
index 0000000000..52937fb115
--- /dev/null
+++ b/tools/intergen/cppgen/include/cppgen/cpp_interface_code_generator.h
@@ -0,0 +1,79 @@
+/**
+ * Copyright (c) 2014, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef CPP_INTERFACE_CODE_GENERATOR_H_
+#define CPP_INTERFACE_CODE_GENERATOR_H_
+
+#include "cppgen/declaration_generator.h"
+#include "cppgen/definition_generator.h"
+
+namespace codegen {
+class Interface;
+class ModuleManager;
+class TypePreferences;
+
+/*
+ * Generates code for all the entities of single interface
+ */
+class CppInterfaceCodeGenerator {
+ public:
+ // Creates code generator for |interface|, using
+ // |module_manager| to find where to output the code
+ CppInterfaceCodeGenerator(const Interface* interface,
+ const TypePreferences* preferences,
+ ModuleManager* module_manager);
+ ~CppInterfaceCodeGenerator();
+ // Generate all the interface code
+ void GenerateCode();
+ private:
+ // Generate code for different interface entities
+ void GenerateEnums();
+ void GenerateStructs();
+ void GenerateTypedefs();
+ void GenerateFunctions();
+ void GenerateResponses();
+ void GenerateNotifications();
+ void GenerateHandlerInterfaces();
+ void GenerateMessageBaseClasses();
+ void GenerateMessageFactories();
+private:
+ // Fields
+ const Interface* interface_;
+ const TypePreferences* preferences_;
+ ModuleManager* module_manager_;
+ DeclarationGenerator declaration_generator_;
+ DefinitionGenerator definition_generator_;
+};
+
+} // namespace codegen
+
+#endif /* CPP_INTERFACE_CODE_GENERATOR_H_ */
diff --git a/tools/intergen/cppgen/include/cppgen/declaration_generator.h b/tools/intergen/cppgen/include/cppgen/declaration_generator.h
new file mode 100644
index 0000000000..6858d6f02e
--- /dev/null
+++ b/tools/intergen/cppgen/include/cppgen/declaration_generator.h
@@ -0,0 +1,109 @@
+/**
+ * Copyright (c) 2014, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef DECLARATION_GENERATOR_H_
+#define DECLARATION_GENERATOR_H_
+
+#include "model/composite_type.h"
+#include "model/constant.h"
+#include "model/function.h"
+
+namespace codegen {
+class CppFile;
+class GeneratorPreferences;
+class ModuleManager;
+class Namespace;
+class TypePreferences;
+
+/*
+ * Generates declaration code of different entities that is to be
+ * put into header file
+ */
+class DeclarationGenerator {
+ public:
+ // Methods
+ DeclarationGenerator(const TypePreferences* preferences,
+ ModuleManager* module_manager);
+ ~DeclarationGenerator();
+
+ // Methods that generate code for different code model entities
+ void GenerateCodeForEnum(const Enum* enm);
+ void GenerateCodeForStruct(const Struct* strct);
+ void GenerateCodeForTypedef(const Typedef* tdef);
+ void GenerateCodeForFunction(const Function& function);
+ void GenerateCodeForResponse(const Response& response);
+ void GenerateCodeForNotification(const Notification& notification);
+ private:
+ // Methods
+ void GenerateCodeForRequest(const Request& response, CppFile* header_file);
+ void GenerateCodeForEnumConstant(const Enum::Constant& enm,
+ CppFile* header_file,
+ bool skip_coma);
+ void GenerateCodeForStructField(const Struct& strct,
+ const Struct::Field& field,
+ CppFile* header_file,
+ Namespace* name_space);
+ void GenerateCodeForStructFields(const Struct& strct,
+ CppFile* header_file,
+ Namespace* name_space);
+ private:
+ // Fields
+ const TypePreferences* preferences_;
+ ModuleManager* module_manager_;
+};
+
+/*
+ * This class is used to add forward declaration of specific type
+ * to file's namespace
+ */
+class TypeForwardDeclarator : public TypeCodeGenerator {
+ public:
+ // Creates objec and automatically forward declares |type| in namespace
+ // |ns|
+ TypeForwardDeclarator(Namespace* ns, const Type* type);
+ private:
+ // TypeCodeGenerator interface
+
+ // Only structs can be forward declared but they can be part of array declaration
+ // All other types don't need forward declaration
+ virtual void GenerateCodeForNullable(const NullableType* nullable);
+ virtual void GenerateCodeForArray(const Array* array);
+ virtual void GenerateCodeForMap(const Map* map);
+ virtual void GenerateCodeForStruct(const Struct* strct);
+ private:
+ // Fields
+ Namespace* ns_;
+};
+
+} // namespace codegen
+
+#endif /* DECLARATION_GENERATOR_H_ */
diff --git a/tools/intergen/cppgen/include/cppgen/definition_generator.h b/tools/intergen/cppgen/include/cppgen/definition_generator.h
new file mode 100644
index 0000000000..21c379f8ea
--- /dev/null
+++ b/tools/intergen/cppgen/include/cppgen/definition_generator.h
@@ -0,0 +1,72 @@
+/**
+ * Copyright (c) 2014, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef DEFINITION_GENERATOR_H_
+#define DEFINITION_GENERATOR_H_
+
+#include "model/builtin_type.h"
+#include "model/function.h"
+
+namespace codegen {
+class CppFile;
+class ModuleManager;
+class Namespace;
+class TypePreferences;
+
+/*
+ * Generates definition code of different entities that is to be
+ * put into implementation (.cc) file
+ */
+
+class DefinitionGenerator {
+ public:
+ DefinitionGenerator(const TypePreferences* preferences,
+ ModuleManager* module_manager);
+ ~DefinitionGenerator();
+
+ void GenerateCodeForEnum(const Enum* enm);
+ void GenerateCodeForStruct(const Struct* strct);
+ void GenerateCodeForFunction(const Function& function);
+ void GenerateCodeForResponse(const Response& response);
+ void GenerateCodeForNotification(const Notification& notification);
+ private:
+ // Methods
+ void GenerateCodeForRequest(const Request& request, CppFile* source_file);
+private:
+ // Fields
+ const TypePreferences* preferences_;
+ ModuleManager* module_manager_;
+};
+
+} // namespace codegen
+
+#endif /* DEFINITION_GENERATOR_H_ */
diff --git a/tools/intergen/cppgen/include/cppgen/enum_from_json_value_function.h b/tools/intergen/cppgen/include/cppgen/enum_from_json_value_function.h
new file mode 100644
index 0000000000..6195d4d247
--- /dev/null
+++ b/tools/intergen/cppgen/include/cppgen/enum_from_json_value_function.h
@@ -0,0 +1,57 @@
+/**
+ * Copyright (c) 2014, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ENUM_FROM_STRING_FUNCTION_H_
+#define ENUM_FROM_STRING_FUNCTION_H_
+
+#include "cppgen/cpp_function.h"
+
+namespace codegen {
+class Enum;
+
+/*
+ * Generates function that translates given string value to JSON value.
+ * Enum constants are serialized/deserialized as strings having value from
+ * predefined set.
+ */
+class EnumFromJsonStringFunction : public CppFunction {
+ public:
+ EnumFromJsonStringFunction(const Enum* enm);
+ ~EnumFromJsonStringFunction();
+ virtual void DefineBody(std::ostream* os) const;
+ private:
+ const Enum* enm_;
+};
+
+} // namespace codegen
+
+#endif /* ENUM_FROM_STRING_FUNCTION_H_ */
diff --git a/tools/intergen/cppgen/include/cppgen/enum_to_json_value_function.h b/tools/intergen/cppgen/include/cppgen/enum_to_json_value_function.h
new file mode 100644
index 0000000000..ce8e39be59
--- /dev/null
+++ b/tools/intergen/cppgen/include/cppgen/enum_to_json_value_function.h
@@ -0,0 +1,54 @@
+/**
+ * Copyright (c) 2014, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ENUM_TO_JSON_VALUE_FUNCTION_H_
+#define ENUM_TO_JSON_VALUE_FUNCTION_H_
+
+#include "cppgen/cpp_function.h"
+
+namespace codegen {
+class Enum;
+
+/*
+ * Generates function that maps enum values to their string representations.
+ */
+class EnumToJsonValueFunction : public CppFunction {
+ public:
+ EnumToJsonValueFunction(const Enum* enm);
+ ~EnumToJsonValueFunction();
+ virtual void DefineBody(std::ostream* os) const;
+ private:
+ const Enum* enm_;
+};
+} // namespace codegen
+
+#endif // ENUM_TO_JSON_VALUE_FUNCTION_H_
diff --git a/tools/intergen/cppgen/include/cppgen/function_id_method.h b/tools/intergen/cppgen/include/cppgen/function_id_method.h
new file mode 100644
index 0000000000..109d46791b
--- /dev/null
+++ b/tools/intergen/cppgen/include/cppgen/function_id_method.h
@@ -0,0 +1,77 @@
+/**
+ * Copyright (c) 2014, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef FUNCTION_ID_METHOD_H_
+#define FUNCTION_ID_METHOD_H_
+
+#include "cppgen/cpp_function.h"
+
+namespace codegen {
+class FunctionMessage;
+
+/*
+ * Generates function_id() virtual method that is to be declared/defined
+ * in every API message struct.
+ */
+class FunctionIdMethod : public CppFunction {
+ public:
+ FunctionIdMethod(const FunctionMessage* func);
+ ~FunctionIdMethod();
+ private:
+ // Methods
+ // CppFunction interface
+ virtual void DefineBody(std::ostream* os) const;
+ private:
+ // Fields
+ const FunctionMessage* func_;
+};
+
+/*
+ * Generates function_string_id() virtual method that is to be declared/defined
+ * in every API message struct.
+ */
+class FunctionStringIdMethod : public CppFunction {
+ public:
+ FunctionStringIdMethod(const FunctionMessage* func);
+ ~FunctionStringIdMethod();
+ private:
+ // Methods
+ // CppFunction interface
+ virtual void DefineBody(std::ostream* os) const;
+ private:
+ // Fields
+ const FunctionMessage* func_;
+};
+
+} // namespace codegen
+
+#endif /* FUNCTION_ID_METHOD_H_ */
diff --git a/tools/intergen/cppgen/include/cppgen/generator_preferences.h b/tools/intergen/cppgen/include/cppgen/generator_preferences.h
new file mode 100644
index 0000000000..5278a24417
--- /dev/null
+++ b/tools/intergen/cppgen/include/cppgen/generator_preferences.h
@@ -0,0 +1,72 @@
+/**
+ * Copyright (c) 2014, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef GENERATOR_PREFERENCES_H_
+#define GENERATOR_PREFERENCES_H_
+
+#include <set>
+#include <string>
+
+
+namespace codegen {
+
+struct TypePreferences {
+ int minimum_interger_size;
+ bool avoid_unsigned;
+ bool generate_json;
+ bool generate_dbus;
+ TypePreferences(int minimum_interger_size,
+ bool avoid_unsigned,
+ bool generate_json,
+ bool generate_dbus);
+};
+
+struct Preferences {
+ Preferences(int minimum_interger_size,
+ bool avoid_unsigned,
+ bool generate_json,
+ bool generate_dbus,
+ const std::set<std::string>& requested_interfaces);
+ TypePreferences type_preferences;
+ std::set<std::string> requested_interfaces;
+};
+
+/*
+ * Text entity names to be used in generated code
+ */
+namespace func_names {
+extern const char* kAdditionalValidation;
+}
+
+} // namespace codegen
+
+#endif /* GENERATOR_PREFERENCES_H_ */
diff --git a/tools/intergen/cppgen/include/cppgen/handler_interface.h b/tools/intergen/cppgen/include/cppgen/handler_interface.h
new file mode 100644
index 0000000000..a7b5a7c924
--- /dev/null
+++ b/tools/intergen/cppgen/include/cppgen/handler_interface.h
@@ -0,0 +1,85 @@
+/* Copyright (c) 2014, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef HANDLER_INTERFACE_H
+#define HANDLER_INTERFACE_H
+
+#include "cppgen/cpp_class.h"
+
+#include "model/function.h"
+#include "utils/stl_utils.h"
+
+namespace codegen {
+class CppFile;
+class Namespace;
+
+/*
+ * Class is used to declare message handler interfaces for specific messages of
+ * given type for given interface
+ */
+class HandlerInterface: public CppClass {
+public:
+ // Methods
+ // Creates HandlerInterface object that is used to produce declaration of
+ // Handler interface. This interface defines handler methods for messages of
+ // given |type| defined in given rpc |interface|.
+ // Interface declaration requires message types to be forward-declared, these
+ // declarations are placed into given |header_file|.
+ HandlerInterface(FunctionMessage::MessageType type,
+ const Interface* interface,
+ CppFile* header_file);
+protected:
+ // Methods
+ // CppClass interface
+ virtual const MethodsList& methods();
+
+private:
+ // Types
+ typedef std::vector<const FunctionMessage*> FunctionMessages;
+private:
+ // Methods
+ // Collects all the messages that are to be handled and defines
+ // Handler methods for them. Also declares virtual destructor.
+ void CollectMethods();
+ // Helper method that actually generates handler functions
+ void AddFunctionMessageHandlers(const FunctionMessages& function_messages);
+private:
+ // Fields
+ FunctionMessage::MessageType type_;
+ const Interface* interface_;
+ CppFile* header_file_;
+ MethodsList methods_;
+ utils::StdContainerDeleter<MethodsList> methods_deleter_;
+};
+
+} // namespace codegen
+
+#endif // HANDLER_INTERFACE_H
diff --git a/tools/intergen/cppgen/include/cppgen/is_valid_enum_function.h b/tools/intergen/cppgen/include/cppgen/is_valid_enum_function.h
new file mode 100644
index 0000000000..b62332e1e5
--- /dev/null
+++ b/tools/intergen/cppgen/include/cppgen/is_valid_enum_function.h
@@ -0,0 +1,56 @@
+/**
+ * Copyright (c) 2014, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef IS_VALID_ENUM_FUNCTION_H_
+#define IS_VALID_ENUM_FUNCTION_H_
+
+#include "cppgen/cpp_function.h"
+
+namespace codegen {
+class Enum;
+
+/*
+ * Generates function that tells whether the value of particular enum is
+ * valid one (belongs to enum values set).
+ */
+class IsValidEnumFunction : public CppFunction {
+ public:
+ IsValidEnumFunction(const Enum* enm);
+ ~IsValidEnumFunction();
+ private:
+ virtual void DefineBody(std::ostream* os) const;
+ const Enum* enm_;
+};
+
+} // namespace codegen
+
+#endif /* IS_VALID_ENUM_FUNCTION_H_ */
diff --git a/tools/intergen/cppgen/include/cppgen/literal_generator.h b/tools/intergen/cppgen/include/cppgen/literal_generator.h
new file mode 100644
index 0000000000..c0818f1b1e
--- /dev/null
+++ b/tools/intergen/cppgen/include/cppgen/literal_generator.h
@@ -0,0 +1,66 @@
+/**
+ * Copyright (c) 2014, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef LITERAL_GENERATOR_H_
+#define LITERAL_GENERATOR_H_
+
+#include <string>
+
+#include "model/constant.h"
+
+namespace codegen {
+
+/*
+ * This class generates string literal representing value of a given constant
+ * depending on constant type.
+ */
+class LiteralGenerator : ConstantCodeGenerator {
+ public:
+ // Literal for |constant| is automatically generated on construction and
+ // can be accessd with result method
+ LiteralGenerator(const Constant& constant);
+ ~LiteralGenerator();
+ // Returns a string value representing given constant
+ std::string result() const;
+ private:
+ // ConstantCodeGenerator interface
+ virtual void GenerateCodeForBooleanConstant(const Boolean::Constant* boolean);
+ virtual void GenerateCodeForIntegerConstant(const Integer::Constant* integer);
+ virtual void GenerateCodeForFloatConstant(const Float::Constant* flt);
+ virtual void GenerateCodeForEnumConstant(const Enum::Constant* enm);
+ private:
+ std::string result_;
+};
+
+} // namespace codegen
+
+#endif /* LITERAL_GENERATOR_H_ */
diff --git a/tools/intergen/cppgen/include/cppgen/message_factory_function.h b/tools/intergen/cppgen/include/cppgen/message_factory_function.h
new file mode 100644
index 0000000000..da63b4453a
--- /dev/null
+++ b/tools/intergen/cppgen/include/cppgen/message_factory_function.h
@@ -0,0 +1,76 @@
+/* Copyright (c) 2014, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef CODEGEN_MESSAGE_FACTORY_FUNCTION_H
+#define CODEGEN_MESSAGE_FACTORY_FUNCTION_H
+
+#include "cppgen/cpp_function.h"
+#include "model/function.h"
+
+namespace codegen {
+class Interface;
+
+/*
+ * This class is used to produce interface-specific,
+ * Message-type specific message factory function that is
+ * to be used to produce message from Json::Value object
+ */
+class MessageFactoryFunction: public CppFunction {
+ public:
+ enum SerializationType {
+ kJson,
+ kDbus
+ };
+
+ // Methods
+ // Creates function code generation object that produces
+ // declaration and definition of a factory for messages of type
+ // |factory_type| that belong to given |interface|
+ MessageFactoryFunction(const Interface* interface,
+ SerializationType serialization_type,
+ FunctionMessage::MessageType factory_type);
+ private:
+ // Types
+ typedef std::vector<const FunctionMessage*> MessageList;
+ private:
+ // Methods
+ virtual void DefineBody(std::ostream* os) const;
+ void DefineCases(std::ostream* os,
+ const MessageList& functions) const;
+ private:
+ // Fields
+ const Interface* interface_;
+ FunctionMessage::MessageType factory_type_;
+};
+
+} // namespace codegen
+
+#endif // CODEGEN_MESSAGE_FACTORY_FUNCTION_H
diff --git a/tools/intergen/cppgen/include/cppgen/message_handle_with_method.h b/tools/intergen/cppgen/include/cppgen/message_handle_with_method.h
new file mode 100644
index 0000000000..6546a38cec
--- /dev/null
+++ b/tools/intergen/cppgen/include/cppgen/message_handle_with_method.h
@@ -0,0 +1,60 @@
+/* Copyright (c) 2014, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef CODEGEN_MESSAGE_HANDLE_WITH_METHOD_H
+#define CODEGEN_MESSAGE_HANDLE_WITH_METHOD_H
+
+#include "cppgen/cpp_function.h"
+
+namespace codegen {
+
+/*
+ * Generates declaration and definiton of HandleWith method
+ * that is required in every structure representing a message.
+ * This method takes Message Handler implementation and calls
+ * Appropriate function on it to handle current message.
+ * (see Visitor pattern).
+ */
+class MessageHandleWithMethod: public CppFunction {
+public:
+ MessageHandleWithMethod(const std::string& class_name);
+
+protected:
+ // CppFunction methods
+ virtual void DefineBody(std::ostream* os) const;
+private:
+ // Fields
+ std::string class_name_;
+};
+
+} // namespace codegen
+
+#endif // CODEGEN_MESSAGE_HANDLE_WITH_METHOD_H
diff --git a/tools/intergen/cppgen/include/cppgen/message_interface.h b/tools/intergen/cppgen/include/cppgen/message_interface.h
new file mode 100644
index 0000000000..8cc2d10b31
--- /dev/null
+++ b/tools/intergen/cppgen/include/cppgen/message_interface.h
@@ -0,0 +1,82 @@
+/* Copyright (c) 2014, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef CODEGEN_MESSAGE_INTERFACE_H
+#define CODEGEN_MESSAGE_INTERFACE_H
+
+#include "cppgen/cpp_class.h"
+#include "model/function.h"
+
+namespace codegen {
+class Interface;
+class MessageInterface;
+
+/*
+ * Helper class that is used to produce code for
+ * interface() method for interface-specific.
+ * message base class.
+ */
+class InterfaceStringIdMethod: public CppClass::Method {
+ public:
+ InterfaceStringIdMethod(
+ const MessageInterface* message_interface,
+ const Interface* interface);
+ protected:
+ // CppFunction interface
+ void DefineBody(std::ostream* os) const;
+ private:
+ const Interface* interface_;
+};
+
+/*
+ * Helper class that is used to produce declaration and
+ * definition of interface-specific message base class
+ * for messages of given type
+ */
+class MessageInterface: public CppClass {
+ public:
+ MessageInterface(const Interface* interface,
+ FunctionMessage::MessageType message_type);
+ private:
+ // Methods
+ // CppClass interface
+ virtual const MethodsList& methods();
+ private:
+ // Fields
+ Method constructor_;
+ Method handle_with_method_;
+ InterfaceStringIdMethod interface_string_id_method_;
+ std::vector<const Method*> methods_;
+};
+
+} // namespace codegen
+
+#endif // CODEGEN_MESSAGE_INTERFACE_H
diff --git a/tools/intergen/cppgen/include/cppgen/module_manager.h b/tools/intergen/cppgen/include/cppgen/module_manager.h
new file mode 100644
index 0000000000..6ec13c9140
--- /dev/null
+++ b/tools/intergen/cppgen/include/cppgen/module_manager.h
@@ -0,0 +1,99 @@
+/**
+ * Copyright (c) 2014, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef MODULE_MANAGER_H_
+#define MODULE_MANAGER_H_
+
+#include <vector>
+
+#include "cppgen/cpp_file.h"
+#include "model/composite_type.h"
+#include "model/function.h"
+
+namespace codegen {
+class Namespace;
+class TypePreferences;
+
+/*
+ * Manages all the source files generated for given interface.
+ * Every interface is a separate module.
+ * Also manages namespaces used to store generated code.
+ */
+class ModuleManager {
+ public:
+ ModuleManager(const std::string& name, const TypePreferences& prefs);
+ ~ModuleManager();
+
+ /*
+ * Methods that are used to find header file for entity that is being
+ * generated
+ */
+ CppFile& HeaderForInterface();
+ CppFile& HeaderForEnum(const Enum& enm);
+ CppFile& HeaderForStruct(const Struct& strct);
+ CppFile& HeaderForTypedef(const Typedef& tdef);
+ CppFile& HeaderForFunction(const Function& function);
+ CppFile& HeaderForResponse(const Response& request);
+ CppFile& HeaderForNotification(const Notification& notification);
+
+ /*
+ * Methods that are used to find implementation file for entity that
+ * is being generated
+ */
+ CppFile& SourceForInterface();
+ CppFile& SourceForEnum(const Enum& enm);
+ CppFile& SourceForStruct(const Struct& strct);
+ CppFile& SourceForFunction(const Function& function);
+ CppFile& SourceForResponse(const Response& request);
+ CppFile& SourceForNotification(const Notification& notification);
+ CppFile& SourceForValidator();
+
+ /*
+ * Creates and writes all the generated code to appropriate files
+ */
+ bool Write();
+private:
+ std::string module_name_;
+ CppFile enums_header_;
+ CppFile enums_source_;
+ CppFile structs_header_;
+ CppFile structs_source_;
+ CppFile functions_header_;
+ CppFile functions_source_;
+ CppFile interface_header_;
+ CppFile interface_source_;
+ CppFile additional_validation_source_;
+};
+
+} // namespace codegen
+
+#endif /* MODULE_MANAGER_H_ */
diff --git a/tools/intergen/cppgen/include/cppgen/namespace.h b/tools/intergen/cppgen/include/cppgen/namespace.h
new file mode 100644
index 0000000000..29207313af
--- /dev/null
+++ b/tools/intergen/cppgen/include/cppgen/namespace.h
@@ -0,0 +1,152 @@
+/**
+ * Copyright (c) 2014, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef NAMESPACE_H_
+#define NAMESPACE_H_
+
+#include <map>
+#include <set>
+#include <sstream>
+#include <string>
+
+namespace codegen {
+
+/*
+ * Represents single C++ namespace where all the declarations and definitions live.
+ * Automatically generates all the namespace scope declarations,
+ * type forward declarations and 'using' type import directives.
+ */
+class Namespace {
+ public:
+ // Types
+ class ForwardDeclaration;
+ class ImportedName;
+ public:
+ // Methods
+ // Constructs unnamed (anonymous) namespace
+ Namespace();
+ // Constructs named namespace
+ explicit Namespace(const std::string& name);
+ Namespace(const Namespace& that);
+ ~Namespace();
+ // Creates (if absent) nested namespace with |name|
+ // and provides access to it.
+ Namespace& nested(const std::string& name);
+ // Namespace ostream, used to write actual code into namespace
+ std::ostream& os();
+ // Add type described with |type_name| forward declaration
+ // to the top of namespace block
+ void ForwardDeclare(const ForwardDeclaration& type_name);
+ // Add import directive for thing described with |name| to the top
+ // of the current namespace block.
+ void ImportName(const ImportedName& name);
+ // Write this namespace and all it's nested namespaces to the given ostream.
+ void Write(std::ostream* os);
+ // Name (relative) of this namespace
+ const std::string& name() const;
+
+ private:
+ // Methods
+ // Tells whether this namespace or any of it's nested namspaces
+ // has non-empty list of forward declarations or using directives
+ bool HasForwardDeclarations();
+ // Tells whether this namespace or any of it's nested namspaces
+ // has any contents
+ bool HasContents();
+ // Output nested namespaces's list of forward declarations and
+ // 'using' import directives followed by this namespace's list of
+ // forward declarations and import directives
+ void WriteForwardDeclarations(std::ostream* os);
+ // Writes all nested namespaces' contents followed by this namespace contents
+ void WriteContents(std::ostream* os);
+ // Writes namespace begin declaratoin
+ void BeginNamespace(std::ostream* os);
+ // Writes namespace end declaration
+ void EndNamespace(std::ostream* os);
+ private:
+ // Types
+ bool global_;
+ std::string name_;
+ std::set<ImportedName> imported_names_;
+ std::set<ForwardDeclaration> forward_declarations_;
+ std::map<std::string, Namespace> nested_;
+ std::stringstream contents_;
+};
+
+/*
+ * Represents namespace forward declaration item
+ */
+class Namespace::ForwardDeclaration {
+ public:
+ // Only classes and structs can be forward-declared
+ enum Type {
+ kClass,
+ kStruct
+ };
+ public:
+ // Constructs forward declaration item of |type| and |name|
+ ForwardDeclaration(Type type, const std::string& name);
+ // Forward declarations are sorted in alphabetical order of their names
+ bool operator<(const ForwardDeclaration& that) const;
+ const std::string& name() const;
+ Type type() const;
+
+ private:
+ Type type_;
+ std::string name_;
+
+};
+
+/*
+ * Represents single namespace import item
+ */
+class Namespace::ImportedName {
+ public:
+ // Imports a |name| into current namespace. |name| must specify fully
+ // qualified name including namespace name from which it is imported.
+ // If |single_name| is false, the whole namespace is imported
+ ImportedName(std::string name, bool single_name);
+ // Imports are sorted by their type (single name or whole namespace)
+ // then by name alphabetically
+ bool operator<(const ImportedName& that) const;
+ const std::string& name() const;
+ bool is_single_name() const;
+
+ private:
+ bool single_name_;
+ std::string name_;
+};
+
+
+} // namespace codegen
+
+#endif /* NAMESPACE_H_ */
diff --git a/tools/intergen/cppgen/include/cppgen/naming_convention.h b/tools/intergen/cppgen/include/cppgen/naming_convention.h
new file mode 100644
index 0000000000..3aef239ea2
--- /dev/null
+++ b/tools/intergen/cppgen/include/cppgen/naming_convention.h
@@ -0,0 +1,94 @@
+/**
+ * Copyright (c) 2014, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef NAMING_CONVENTION_H_
+#define NAMING_CONVENTION_H_
+
+#include <string>
+#include <vector>
+
+namespace codegen {
+class Interface;
+
+/*
+ * Helper class that constructs word list from a sentence or
+ * single-word identifier written in UPPER_CASE, lower_case,
+ * camelCase or UpperCamelCase and provides conversion between these
+ * identifier naming conventions.
+ */
+class WordList {
+ public:
+ WordList();
+ ~WordList();
+ // Guess identifier naming convention and construct WordList from it
+ static WordList FromUnknown(const std::string& identifier);
+ // Split identifier as UPPER_CASE_ONE, also used to split
+ // lower_case_identifiers
+ static WordList FromUnderscoreSeparated(const std::string& identifier);
+ // Split identifier as camelCase identifier or upperCamelCase
+ static WordList FromCamelCase(const std::string& identifier);
+ // Concatenates |that| word list to this one producing single word list
+ WordList& operator+=(const WordList& that);
+ // Converts word list to one of the supported identifier naming conventions
+ std::string ToUpperCase() const;
+ std::string ToCamelCase() const;
+ std::string ToLowerCase() const;
+ std::string ToUpperCamelCase() const;
+ // Produces lower-case abbreviaton of a given WordList
+ std::string Abbreviate() const;
+
+ private:
+ // Normalizes word list: all words are converted to lower case,
+ // spaces are trimmed
+ void Normalize();
+ std::vector<std::string> words_;
+};
+
+// Capitalizes given string
+std::string Capitalize(const std::string& str);
+
+// Translate interface name to lower case
+std::string LowercaseIntefaceName(const Interface& interface);
+
+std::string UpperCamelCaseInterfaceName(const Interface& interface);
+
+// Produces namespace name for |interface|.
+// Currently it just lower_case_interface_name
+std::string InterfaceNamespaceName(const Interface& interface);
+
+// Produces new name (generally for struct fields) if it
+// conflicts with known keywords
+std::string AvoidKeywords(const std::string& name);
+
+} // namespace codegen
+
+#endif /* NAMING_CONVENTION_H_ */
diff --git a/tools/intergen/cppgen/include/cppgen/struct_type_constructor.h b/tools/intergen/cppgen/include/cppgen/struct_type_constructor.h
new file mode 100644
index 0000000000..a9f5ffec1d
--- /dev/null
+++ b/tools/intergen/cppgen/include/cppgen/struct_type_constructor.h
@@ -0,0 +1,71 @@
+/**
+ * Copyright (c) 2014, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef STRUCT_TYPE_CONSTRUCTOR_H_
+#define STRUCT_TYPE_CONSTRUCTOR_H_
+
+#include "cppgen/cpp_function.h"
+
+namespace codegen {
+class Struct;
+class TypePreferences;
+
+/*
+ * Generates code of struct default constructor without parameters
+ */
+class StructTypeDefaultConstructor : public CppStructConstructor {
+ public:
+ StructTypeDefaultConstructor(const Struct* strct,
+ const std::string& base_class_name);
+ ~StructTypeDefaultConstructor();
+ private:
+};
+
+/*
+ * Generates code of struct mandatory constructor.
+ * Mandatory constructor is a constructor that requires values for all
+ * mandatory fields to be passed as parameters.
+ */
+class StructTypeMandatoryConstructor : public CppStructConstructor {
+ public:
+ StructTypeMandatoryConstructor(const TypePreferences* preferences,
+ const Struct* strct,
+ const std::string& base_class_name);
+ ~StructTypeMandatoryConstructor();
+ private:
+ // CppFunction pure virtual methods implementation
+ virtual void DefineBody(std::ostream* os) const;
+};
+
+} // namespace codegen
+
+#endif /* STRUCT_TYPE_CONSTRUCTOR_H_ */
diff --git a/tools/intergen/cppgen/include/cppgen/struct_type_dbus_serializer.h b/tools/intergen/cppgen/include/cppgen/struct_type_dbus_serializer.h
new file mode 100644
index 0000000000..64872f3265
--- /dev/null
+++ b/tools/intergen/cppgen/include/cppgen/struct_type_dbus_serializer.h
@@ -0,0 +1,88 @@
+/* Copyright (c) 2014, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef CPPGEN_STRUCT_TYPE_DBUS_SERIALIZER_H
+#define CPPGEN_STRUCT_TYPE_DBUS_SERIALIZER_H
+
+#include "cppgen/cpp_function.h"
+
+namespace codegen {
+class Interface;
+class Struct;
+class TypePreferences;
+
+class StructTypeDbusMessageSignatureMethod: public CppFunction {
+ public:
+ StructTypeDbusMessageSignatureMethod(const TypePreferences* preferences,
+ const Struct* strct,
+ bool substructure);
+ ~StructTypeDbusMessageSignatureMethod();
+ private:
+ // CppFunction interface
+ void DefineBody(std::ostream* os) const;
+ private:
+ const TypePreferences* preferences_;
+ bool substructure_;
+ const Struct* strct_;
+};
+
+class StructTypeFromDbusReaderConstructor : public CppStructConstructor {
+ public:
+ StructTypeFromDbusReaderConstructor(const TypePreferences* preferences,
+ const Struct* strct,
+ bool substructure,
+ const std::string& base_class_name);
+ ~StructTypeFromDbusReaderConstructor();
+ private:
+ // CppFunction interface
+ void DefineBody(std::ostream* os) const;
+ private:
+ const TypePreferences* preferences_;
+ bool substructure_;
+ const Struct* strct_;
+};
+
+class StructTypeToDbusWriterMethod : public CppFunction {
+ public:
+ StructTypeToDbusWriterMethod(const Struct* strct,
+ bool substructure);
+ ~StructTypeToDbusWriterMethod();
+ private:
+ // CppFunction interface
+ void DefineBody(std::ostream* os) const;
+ private:
+ bool substructure_;
+ const Struct* strct_;
+};
+
+} // namespace codegen
+
+#endif // CPPGEN_STRUCT_TYPE_DBUS_SERIALIZER_H
diff --git a/tools/intergen/cppgen/include/cppgen/struct_type_from_json_method.h b/tools/intergen/cppgen/include/cppgen/struct_type_from_json_method.h
new file mode 100644
index 0000000000..270fe30248
--- /dev/null
+++ b/tools/intergen/cppgen/include/cppgen/struct_type_from_json_method.h
@@ -0,0 +1,73 @@
+/**
+ * Copyright (c) 2014, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef STRUCT_TYPE_FROM_JSON_METHOD_H_
+#define STRUCT_TYPE_FROM_JSON_METHOD_H_
+
+#include "cppgen/cpp_function.h"
+
+namespace codegen {
+class Struct;
+
+/*
+ * Generates struct constructor that assigns fields values taking them from
+ * parsed json tree
+ */
+class StructTypeFromJsonConstructor : public CppStructConstructor {
+ public:
+ StructTypeFromJsonConstructor(const Struct* strct,
+ const std::string& base_class_name);
+ ~StructTypeFromJsonConstructor();
+ private:
+ // CppFunction pure virtual methods implementation
+ virtual void DefineBody(std::ostream* os) const;
+ private:
+ // Fields
+ const Struct* strct_;
+};
+
+/*
+ * Generates struct method that serializes the struct fields into json tree.
+ */
+class StructTypeToJsonMethod : public CppFunction {
+ public:
+ StructTypeToJsonMethod(const Struct* strct);
+ ~StructTypeToJsonMethod();
+ private:
+ // CppFunction pure virtual methods implementation
+ virtual void DefineBody(std::ostream* os) const;
+ private:
+ const Struct* strct_;
+};
+} // namespace codegen
+
+#endif /* STRUCT_TYPE_FROM_JSON_METHOD_H_ */
diff --git a/tools/intergen/cppgen/include/cppgen/struct_type_is_initialized_method.h b/tools/intergen/cppgen/include/cppgen/struct_type_is_initialized_method.h
new file mode 100644
index 0000000000..48e2d761f0
--- /dev/null
+++ b/tools/intergen/cppgen/include/cppgen/struct_type_is_initialized_method.h
@@ -0,0 +1,76 @@
+/**
+ * Copyright (c) 2014, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef STRUCT_TYPE_IS_INITIALIZED_METHOD_H_
+#define STRUCT_TYPE_IS_INITIALIZED_METHOD_H_
+
+#include "cppgen/cpp_function.h"
+
+namespace codegen {
+class Struct;
+
+/*
+ * Generates struct method that is used to tell whether at least
+ * one of struct fields have been initialized
+ */
+class StructTypeIsInitializedMethod : public CppFunction {
+ public:
+ StructTypeIsInitializedMethod(const Struct* strct);
+ ~StructTypeIsInitializedMethod();
+ private:
+ // CppFunction pure virtual methods implementation
+ virtual void DefineBody(std::ostream* os) const;
+ private:
+ // Fields
+ const Struct* strct_;
+};
+
+/**
+ * @brief Generates bool empty() method for struct types
+ * this method has no is_ prefix to support stl style
+ * that is dictated by maps and arrays
+ */
+class StructTypeStructEmptyMethod : public CppFunction {
+ public:
+ StructTypeStructEmptyMethod(const Struct* strct);
+ ~StructTypeStructEmptyMethod();
+ private:
+ // CppFunction pure virtual methods implementation
+ virtual void DefineBody(std::ostream* os) const;
+ private:
+ // Fields
+ const Struct* strct_;
+};
+
+} // namespace codegen
+
+#endif /* STRUCT_TYPE_IS_INITIALIZED_METHOD_H_ */
diff --git a/tools/intergen/cppgen/include/cppgen/struct_type_is_valid_method.h b/tools/intergen/cppgen/include/cppgen/struct_type_is_valid_method.h
new file mode 100644
index 0000000000..284f7ba45e
--- /dev/null
+++ b/tools/intergen/cppgen/include/cppgen/struct_type_is_valid_method.h
@@ -0,0 +1,72 @@
+/**
+ * Copyright (c) 2014, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef STRUCT_TYPE_IS_VALID_METHOD_H_
+#define STRUCT_TYPE_IS_VALID_METHOD_H_
+
+#include "cppgen/cpp_function.h"
+
+namespace codegen {
+class Struct;
+
+/*
+ * Generates a method that is used to tell whether all the
+ * struct fields have valid values
+ */
+class StructTypeIsValidMethod : public CppFunction {
+ public:
+ StructTypeIsValidMethod(const Struct* strct);
+ ~StructTypeIsValidMethod();
+ private:
+ // CppFunction pure virtual methods implementation
+ virtual void DefineBody(std::ostream* os) const;
+ const Struct* strct_;
+};
+
+/*
+ * Generates empty struct method stub that is to be edited by
+ * generated code user to implement additional validation that could not be
+ * defined in API XML specification
+ */
+class StructTypeAdditionalValidationMethod : public CppFunction {
+ public:
+ StructTypeAdditionalValidationMethod(const Struct* strct);
+ ~StructTypeAdditionalValidationMethod();
+ private:
+ // CppFunction pure virtual methods implementation
+ virtual void DefineBody(std::ostream* os) const;
+ const Struct* strct_;
+};
+
+} // namespace codegen
+
+#endif /* STRUCT_TYPE_IS_VALID_METHOD_H_ */
diff --git a/tools/intergen/cppgen/include/cppgen/struct_type_report_erros_method.h b/tools/intergen/cppgen/include/cppgen/struct_type_report_erros_method.h
new file mode 100644
index 0000000000..3dd851ccc4
--- /dev/null
+++ b/tools/intergen/cppgen/include/cppgen/struct_type_report_erros_method.h
@@ -0,0 +1,53 @@
+/* Copyright (c) 2014, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef CPPGEN_STRUCT_TYPE_REPORT_ERROS_METHOD_H
+#define CPPGEN_STRUCT_TYPE_REPORT_ERROS_METHOD_H
+
+#include "cppgen/cpp_function.h"
+
+namespace codegen {
+class Struct;
+
+class StructTypeReportErrosMethod: public CppFunction {
+ public:
+ StructTypeReportErrosMethod(const Struct* strct);
+ private:
+ // CppFunction pure virtual methods implementation
+ virtual void DefineBody(std::ostream* os) const;
+ private:
+ // Fields
+ const Struct* strct_;
+};
+
+} // namespace codegen
+
+#endif // CPPGEN_STRUCT_TYPE_REPORT_ERROS_METHOD_H
diff --git a/tools/intergen/cppgen/include/cppgen/type_name_code_generator.h b/tools/intergen/cppgen/include/cppgen/type_name_code_generator.h
new file mode 100644
index 0000000000..5fd75760aa
--- /dev/null
+++ b/tools/intergen/cppgen/include/cppgen/type_name_code_generator.h
@@ -0,0 +1,153 @@
+/**
+ * Copyright (c) 2014, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef TYPE_NAME_CODE_GENERATOR_H_
+#define TYPE_NAME_CODE_GENERATOR_H_
+
+#include "model/type.h"
+
+#include <sstream>
+
+namespace codegen {
+class Interface;
+class Type;
+class TypePreferences;
+
+/*
+ * These visitor classes are used to generate C++ type name for given
+ * model types.
+ */
+
+/*
+ * Generates primitive or STL type name for given model type.
+ * Used to generate struct constructor parameters.
+ */
+class TypeNameGenerator: public TypeCodeGenerator {
+ public:
+ // Generates primitive type name for |type|.
+ // |interface| specifies the interface where code is currently
+ // being generated. Depending on that relative or fully qualified
+ // type names are generated.
+ // Generates type name can be accessed with result() method.
+ TypeNameGenerator(const Interface* interface,
+ const TypePreferences* preferences,
+ const Type* type);
+ ~TypeNameGenerator();
+ // Generated type name
+ std::string result() const;
+ private:
+ virtual void GenerateCodeForBoolean(const Boolean* boolean);
+ virtual void GenerateCodeForInteger(const Integer* integer);
+ virtual void GenerateCodeForFloat(const Float* flt);
+ virtual void GenerateCodeForString(const String* string);
+ virtual void GenerateCodeForEnum(const Enum* enm);
+ virtual void GenerateCodeForArray(const Array* array);
+ virtual void GenerateCodeForMap(const Map* map);
+ virtual void GenerateCodeForNullable(const NullableType* nullable);
+ virtual void GenerateCodeForStruct(const Struct* strct);
+ virtual void GenerateCodeForTypedef(const Typedef* tdef);
+
+ private:
+ const Interface* interface_;
+ const TypePreferences* preferences_;
+ bool prefer_reference_type_;
+ std::stringstream os_;
+};
+
+/*
+ * Generates type name from rpc_base template library.
+ * Used to define struct fields.
+ */
+class RpcTypeNameGenerator: public TypeCodeGenerator {
+ public:
+ // Types
+ public:
+ // Generates name of type that is able to validate given primitive value
+ // |interface| specifies the interface where code is currently
+ // being generated. Depending on that relative or fully qualified
+ // type names are generated.
+ // Depending on |availability| option optionally wraps declaration into
+ // Mandatory or Optional template
+ RpcTypeNameGenerator(const Interface* interface,
+ const TypePreferences* preferences,
+ const Type* type,
+ bool optional);
+ ~RpcTypeNameGenerator();
+ // Generated type name
+ std::string result() const;
+ private:
+ // TypeCodeGenerator methods
+ virtual void GenerateCodeForBoolean(const Boolean* boolean);
+ virtual void GenerateCodeForInteger(const Integer* integer);
+ virtual void GenerateCodeForFloat(const Float* flt);
+ virtual void GenerateCodeForString(const String* string);
+ virtual void GenerateCodeForEnum(const Enum* enm);
+ virtual void GenerateCodeForArray(const Array* array);
+ virtual void GenerateCodeForMap(const Map* map);
+ virtual void GenerateCodeForNullable(const NullableType* nullable);
+ virtual void GenerateCodeForStruct(const Struct* strct);
+ virtual void GenerateCodeForTypedef(const Typedef* tdef);
+ private:
+ const Interface* interface_;
+ const TypePreferences* preferences_;
+ std::stringstream os_;
+};
+
+/*
+ * Not a real code generator but helper class that is used to collect
+ * properties of composite types
+ */
+class TypeProperties: public TypeCodeGenerator {
+public:
+ TypeProperties(const Type* type);
+ // Tells whether type is map, array or typedef alias of map or array
+ bool is_container() const;
+
+private:
+ // TypeCodeGenerator methods
+ virtual void GenerateCodeForBoolean(const Boolean* boolean);
+ virtual void GenerateCodeForInteger(const Integer* integer);
+ virtual void GenerateCodeForFloat(const Float* flt);
+ virtual void GenerateCodeForString(const String* string);
+ virtual void GenerateCodeForEnum(const Enum* enm);
+ virtual void GenerateCodeForArray(const Array* array);
+ virtual void GenerateCodeForMap(const Map* map);
+ virtual void GenerateCodeForNullable(const NullableType* nullable);
+ virtual void GenerateCodeForStruct(const Struct* strct);
+ virtual void GenerateCodeForTypedef(const Typedef* tdef);
+private:
+ bool container_;
+};
+
+} // namespace codegen
+
+#endif /* TYPE_NAME_CODE_GENERATOR_H_ */