-
Notifications
You must be signed in to change notification settings - Fork 11
Polymorphic
GRAS needed a polymorphic container that was extensible and could bridge the languages C++ and python. For this reason, PMC (Polymorphic Container) library was created. And because PMC is its own library, it can be used in any project, not just GRAS.
See the PMC homepage for more detail: https://github.com/guruofquality/PMC/wiki
PMC is simply a container class with a few API methods, so its simple, easy to learn, and just about any type can be contained in a PMC. imagine PMC like a more advanced version of boost::any.
- Seamless language transition:
When using C++, users interact with primitive data types and STL. When using python, users interact with built-in python types. PMC understands how to translate most basic types and containers between the languages. Example: Want a dictionary object? Use std::map in C++, use dict in python. PMC can support almost any data type that you can throw at it.
- Type safety/const-correctness:
Its important that once the container object is passed downstream, that the consumer cannot modify the contained object. If we allowed modification, there would be a race condition among multiple downstream consumers since they are holding referenced copies of the same object. A PMC object can be passed downstream as a read-only PMCC object. The contained object cannot be modified.
- Extensible for new types:
Any C++ type with an equality operator can be used with PMC. But bridging the GAP into python is a little more involved. The PMC python module comes with support for most native data types. And the type registry system allows users to add any custom type. More on this in the next section:
GRAS uses PMC to:
- Pass messages between blocks
- Tag stream items with metadata
- Implement properties interface
- Python support for GRAS types
The PMC type is literally sprinkled all over GRAS; sometimes in the background, sometimes in the API. Its not just the tags and the messages, which is the obvious application for PMC. The properties interface doesnt expose even one call with PMC, yet PMC is the reason the properties interface calls are completely type agnostic in either language; and how either language can easily call into the other's properties interface.
Remember how PMC is extensible? Many users will not even notice this, but many of the GRAS objects are actually registered into PMC so they can be seamlessly used in python. The SBuffer class, StreamTag type, and PacketMsg type are all examples.