Registers a Base or Derived Class into a generic template functor to facilitate the creation of shape objects based on a buffer restored from a file, enabling seamless serialization and deserialization of diverse base-derived objects.
- Easy to implement and add new shape.
- Automatic shape factory registration for each derived base class - REGISTER_SHAPE(TYPE)
- BaseFactory - Register a shape generator with a specific type name, using registerShapeGenerator for registration of ShapeFactoryBase
- Implemented ShapeFactory for creating and Saving Shapes from buffer (serialization/Deserialization to and from file)
- InArchive and OutArchive for Creating and for serialization/Deserialization to and from file
Three Shapes:
- Base (Abstract class)
- Point
- Circle
Factories:
- BaseFactory - Singleton Factory for creating shape objects
- ShapeFactoryBase - Base class for ShapeFactory
- ShapeFactory - serialization/Deserialization to and from file. Registered and used as Fuctor and std:: Function, using BaseFactory::get().registerShapeGenerator(shape type, ShapeFactory)
- REGISTER_SHAPE(TYPE) - Register shape class and compatible ShapeFactory for serialization/Deserialization
Mangers:
- Archive - Contains Shapes vector. Add Shapes.
- InArchive - Shape Serialization into file. Draw Shape.
- OutArchive - Shape Deserialization from file. Draw Shape.
DrawMe.exe in the most generic way it could be done, without using boost Serialization nor Google Prototype Buffer mechanism (both and all solutions, register class type as it can’t be done otherwise in C++)
- Shapes aren’t involved in the way they are saved or loaded and file format
- Deserialization is the same for any Base Derived class using Class Factory, and Template solution
How To Run:
- ./DrawMe.exe -h
- ./DrawMe.exe -s out.dat - Shape Serialization into file
- ./DrawMe.exe -d out.dat - Shape Deserialization from file.
Running Examples: PS C:\Dev\DrawMe\x64\Release> ./DrawMe.exe -h Running main logic... usage: DrawMe [-d <file_name> shape filename to deserialize shapes from(default out.dat) -s<file_name>shape filename for shapes serialization (default out.dat)] Main logic completed successfully.
PS C:\Dev\DrawMe\x64\Release> ./DrawMe.exe -s out.dat Running main logic... Object Name: Base Object Name: Point, Draw: x = 3.200000 y = 4.500000 Object Name: Circle, Draw: radius = 9, x = 7.200000 y = 9.300000 Object Name: Point, Draw: x = 4.500000 y = 7.500000 Object Name: Circle, Draw: radius = 20, x = 1.500000 y = 2.400000 Object Name: Circle, Draw: radius = 22, x = 1.600000 y = 5.400000 Object Name: Circle, Draw: radius = 23, x = 1.700000 y = 6.400000
Finshed Saving and Drawing ThemMain logic completed successfully.
PS C:\Dev\DrawMe\x64\Release> ./DrawMe.exe -d out.dat Running main logic... Object Name: Base Object Name: Point, Draw: x = 3.200000 y = 4.500000 Object Name: Circle, Draw: radius = 9, x = 7.200000 y = 9.300000 Object Name: Point, Draw: x = 4.500000 y = 7.500000 Object Name: Circle, Draw: radius = 20, x = 1.500000 y = 2.400000 Object Name: Circle, Draw: radius = 22, x = 1.600000 y = 5.400000 Object Name: Circle, Draw: radius = 23, x = 1.700000 y = 6.400000
Finshed Loading Shapes and Drawing ThemMain logic completed successfully.