The PropertyPublisher interface allows a class to publish a collection of properties described using the PropDescriptor format.

The methods don't have to be implemented by hand as it's automatically done when the PropertyPusblisherImpl template is mixed in a class.

Inspiration: The semantic used for this interface is inspired by the Object-Pascal "published" protection attribute. In pascal, "published" causes the member (called a property) to have the matching RTTI emitted. They are used to stream objects, to build IDE inspectors, bindings list, etc.

This interface (as well as its default implementation) reproduces a similar system. Instead of "published", there are anotations, instead of the RTTI tree structure there is an array of PropDescriptor.



Object declarator()
void declarator(Object value)

Pointer to the object that has created the descriptor leading to this PropertyPublisher instance.

size_t publicationCount()

Returns the count of descriptor this class publishes.

GenericDescriptor* publicationFromIndex(size_t index)

Returns a pointer the index-th descriptor. Index must be within the [0 .. publicationCount] range.

GenericDescriptor* publicationFromName(const(char)[] name)

Returns a pointer to a descriptor according to its name. Similar to the publication() function template excepted that the result type has not to be specified.


1 import iz.streams;
2 static class StuffPublisher: PropertyPublisher
3 {
4     // implements the interface as well as other usefull functions.
5     mixin PropertyPublisherImpl;
7     protected:
8         @SetGet char[] _name = "Fantomas".dup;
9         @SetGet ubyte _age = 33;
10         MemoryStream _opaque;
12     public:
13         this()
14         {
15             // scans the stuff anotated with @GetSet, @Set, @Get
16             collectPublications!StuffPublisher;
17             _opaque = construct!MemoryStream;
18         }
19         ~this() {destruct(_opaque);}
21         @Set void opaque(Stream stream)
22         {
23             _opaque.loadFromStream(stream);
24         }
25         @Get Stream opaque()
26         {
27             return _opaque;
28         }
29 }
31 StuffPublisher stuffPublisher = construct!StuffPublisher;
32 // 3 publications are available: name, age and opaque.
33 // they will be handled automatically when binding or serializing.
34 assert(stuffPublisher.publicationCount == 3);
35 // One way to access the publications
36 assert(stuffPublisher.publication!(char[])("name").get == "Fantomas");
37 destruct(stuffPublisher);