Coder Social home page Coder Social logo

cpqd / cstructgen Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fnchooft/cstructgen

0.0 5.0 0.0 2.77 MB

GSL-Template C++ CodeGenerator for the automatic generation of compare, toString, toJson, fromJson-helpers based on castxml

Makefile 6.24% Shell 54.49% M4 24.64% XSLT 14.64%

cstructgen's Introduction

Build Status

Code-generator for C/C++-Structs based on CASTXML gccxml-output

In the case existing C-Structs are used in a project, the need occurs to have compare-operators, toString-functions and maybe the occasional json-serializer and json-deserializer function.

Since a C-Struct has a well-defined structure, the CastXML-tool can be used to generate a C-family abstract syntax tree XML-representation of the struct. This XML-representation can then be transformed by using the GSL-language.

Purpose

  • Minimal to no code-changes in existing code
  • Analyze C / C++ -Structs
  • Generate XML-representation with the CastXML-tool
  • Transform XML to C++-code

Dependencies

What is implemented?

Since the gccxml-syntax is well structured, the following entities are analyzed/handled:

  • FundamentalTypes

    • uint8_t, 16,32,64
    • int8_t, 16,32,64
    • float, double
    • Typedefs to FundamentalTypes
    • std::vector, std::list, std::pair
    • std::map<K,V>
      • K,V must either be a FundamentalType, or a predefined Struct
      • ** std::map << K , std::vector|list|pair >> is not supported for now **
  • Enumerations

  • Old style C++

  • New style C11 (not yet supported)

  • Typedefs

    • Mostly tested typedef to Struct,FundamentalType
  • Unions

    • Following assumption is made: The classifier of which union-Choice is to be used is conditioned by a previously defined Field ( in the same Struct).
    • By stipulating the condition for which this Union-Choice is valid in a seperate xyz.settings.xml file, we can generate the needed printers (toString, streaming) and json-serializer and json-deserializer code.
  • std::list, std::vector

    • Are represented as Class-entities, and for these cases the generator is working.
  • std::pair is converted by C++ into a Struct with first- and second-members.

Examples

  • See the examples-directory for use cases.

Author

Notes / Limitations

  • The generator was conceived to run once under the control of the programmer.
  • Other then jsonxx, there are no special requirements and the generated code should run, and is running on very limited hardware such as mk6800 etc.
  • a precompiled castxml-utility can be downloaded directly from ITK by following these instructions.

Special thanks

  • All the authors of the dependencies, gsl, castxml and jsonxx.

  • Inspired by: cjson

  • pygccxml

    • This library can also read the gccxml-output, but needs a python-infrastructure.

Open Issues / Todos

  • Add comments in generated artifacts
  • Cleanup test-includes for gtest
  • Add sha1sum of input-file in generated artifacts
  • Add better float comparison handling (floating-point according to IEEE754 standard)
  • Tests ( json ser, json deser )
  • Add Examples for meta-data injection ( structs, compare functions, union-serialization )
  • Add Tests for meta-data injection ( structs, compare functions, union-serialization )

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.