Integration

A guide on how to integrate GPDS into a project.

Overview

GPDS can be built as a static or dynamic (shared) library.

see Building to learn how to build the library.

Requirements

Using GPDS only requires a C++17 compatible compiler (and corresponding STL). Furthermore, GPDS uses cmake as the primary build system.

Integration - CMake

Integrating GPDS into a client application that also uses cmake is extremely easy as GPDS properly exports the library targets.

  1. Install the library. See Building for instructions.
  2. Include the GPDS package into the client application cmake list using find_package():
    find_package(gpds REQUIRED)
  3. Link the GPDS library either statically or dynamically to the client application/library:

    Link dynamically:

    target_link_libraries(my-application gpds::gpds-shared)

    or link statically:

    target_link_libraries(my-application gpds::gpds-static)

Integration - Application

After integrating the GPDS library into a client application/library, classes can inherit the gpds::serialize interface.

  1. Make your class(es) inherit the gpds::serialize interface:
    #include <gpds/serialize.h>
    
    class my_class : public gpds::serialize
    {
    };
  2. Implement the to_container() and from_container() interface functions:
    #include <gpds/serialize.h>
    
    class my_class : public gpds::serialize
    {
        virtual gpds::container to_container() const override {
            gpds::container c;
    
            // Add values & attributes here...
    
            return c;
        }
    
        virtual void from_container(const gpds::container& c) override {
            // Load values & attributes here...
        }
    };
  3. Wherever appropriate in the client application/library, use the archiver to serialize:
    #include <fstream>
    #include <gpds/archiver_xml.h>
    
    int main()
    {
        // Object to serialize
        my_class c;
    
        // Create & open file
        std::ofstream ofile;
        ofile.open("data.xml");
    
        // Serialize to file
        gpds::archiver_xml ar;
        ar.save(ofile, c, "my_class");
    
        // Close file
        ofile.close();
    
        return 0;
    }
    
  4. Wherever appropriate in the client application/library, use the archiver to deserialize:
    #include <fstream>
    #include <gpds/archiver_xml.h>
    
    int main()
    {
        // Object to serialize
        my_class c;
    
        // Create & open file
        std::ifstream ifile;
        ifile.open("data.xml");
    
        // Deserialize from file
        ar.load(ifile, c, "my_class");
    
        // Close file
        ifile.close();
    
        return 0;
    }