Guest
|
Posted: Thu May 17, 2007 1:07 am Post subject: newbie conceptual questions on generic programming |
|
|
I'm returning to C++ after a considerable time away from it (about 8
years since I last used it professionally), and of course in the
meantime the changes have been vast. I've been burying myself in books
about templates, STL, boost, generic programming, african swallow
migratory patterns, etc, and I'm finding that my uptake is too slow to
verify within a reasonable time that what I want to do is even
possible and/or practical.
To get my feet wet again in C++ after so long, my supervisor has
picked what should have been a simple project, to develop a class to
represent a row of data in a table. Here's a list of features we'd
like this class to have:
* Should provide a base class or a template from which table-specific
classes can be derived or specialized
* Each resulting object should contain fields, each of which knows
whether it's been modified since loading from the database, flatfile,
etc
* Obviously, the fields will each have to support different data
types. I could use Boost.Any for this, but this seems oriented toward
cases where the types are not known until runtime. I will know all the
types for a given table's list of columns at compile time, so I'd
rather specify them there.
* The row object should be able to iterate through all the fields it
contains, knowing which have changed, and assemble the appropriate
UPDATE statement. This means the fields will need to be stored in a
vector or an array or similar, not just as simple member variables on
an object.
* Each field, in addition to instance-specific properties like "is
null" and "has been modified", needs to support schema-specific
characteristics, like "should lazy load" and "column name in
database". These latter data items should obviously exist in only one
place for a particular table schema.
* Syntax to specify a particular table's representation as a C++ class
or template specialization should be relatively compact, with all
necessary details in a single code file
However I implement it, the classes in question *must* be high-
performance in creation and destruction, as it will be used for an
extremely high-throughput database operation. So for example, what I
want to avoid is a constructor that must allocate data foir the schema
details column-by-column during instantiation. I think templates and
generic programming are ideal for this sort of thing, trading code
size for execution speed. This is exactly what I want -- I don't care
if the compiled code is huge, as long as it runs quickly.
While I'm not looking for anyone to do this for me, I'd like at least
to know if this should be possible, and maybe a basic approach one
might take. The examples I've seen of MPL metaprogramming allowing
YACC-like functionality in C++ code are exciting and compelling, but
I'm still struggling to understand enough to apply such ideas.
Are there similar examples out there that I can look at? Has anyone
done anything like this with C++? I'm happy to clarify if any of the
above is confusing or unclear.
Thanks!
--chris
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|