Django comes with this great approach, where all you have todo is write your data model, and Django will generate the correct (most basic) view according to your model properties.
E.g:
class Article(models.Model):
pub_date = models.DateTimeField()
headline = models.CharField(max_length=200)
content = models.TextField()
reporter = models.ForeignKey(Reporter)
def __unicode__(self):
return self.headline
Any forms displayed by Django will already use the correct and appropriate field type that matches the property type (DateTimeField, CharField, TextField, etc).
I was wondering whether the same is possible with C++? I’m thinking of writing an application settings class, and I don’t want to build the dialog window by hand. I’d prefer if I could build a dialog automatically. I don’t care about the order and position of the individual input-fields. I think that this should be possible, given that I follow the Model View Controller pattern anyway.
EDIT I’d appreciate it if answers could include example code or links to examples.
In C++ there is no reflection mechanism allowing you to query members of a class, so it is not possible to achieve what you want as easily as in Python. But, you can apply techniques used by C++ serialization libraries, for example Boost. In essence, you need to add to your class an equivalent of the boost serialization
serializemethod, which will compensate for the lack of the reflection facilities needed to retrieve information on class’ members, here is a boost serialization tutorial explaining this: http://www.boost.org/doc/libs/1_35_0/libs/serialization/doc/serialization.html.Another option, also used by some C++ serialization systems, is to parse the C++ class source code and generate C++ code which does the serialization (in your case that would be generating GUI dialogs as well).