template<class T>
Printer class
Base template for printing objects to streams.
| Template parameters | |
|---|---|
| T | Type of object to print |
Abstract base class template for printing objects to streams.
The Printer class provides a common interface for writing objects of type T to output streams. This class serves as the foundation for specialized printers that handle different file formats and object types.
Derived classes must implement:
- print(std::
ostream&) - Write object to an output stream - getObject() - Access the object being printed
Usage Example
class MyObjectPrinter : public Printer<MyObject> { public: MyObjectPrinter(const MyObject& obj) : m_object(obj) {} void print(std::ostream& os) override { // Write object to stream os << getObject(); } const ObjectType& getObject() const override { return m_object; } private: const MyObject& m_object; }; // Usage MyObject obj; MyObjectPrinter printer(obj); printer.print(std::cout);
Public types
- using ObjectType = T
- Type of object being printed.
Public functions
- void print(std::ostream& os) pure virtual
- Prints object to an output stream.
- auto getObject() const -> const ObjectType& pure virtual
- Gets a const reference to the object being printed.
Function documentation
template<class T>
void Rodin:: IO:: Printer<T>:: print(std::ostream& os) pure virtual
Prints object to an output stream.
| Parameters | |
|---|---|
| os in/out | Output stream to write to |
This pure virtual method must be implemented by derived classes to write the object data to the provided stream.
template<class T>
const ObjectType& Rodin:: IO:: Printer<T>:: getObject() const pure virtual
Gets a const reference to the object being printed.
| Returns | Const reference to the object |
|---|
This method provides read-only access to the object being written. Derived classes must implement this to return their internal object reference.