Hi,
I'm currently working on ticket #124 and thought I'll let you know what
I intend to do, so you can stop me from introducing any unmaintainable
garbage ;)
My current design should be able to deliver the same features as the
current OSB loader, but without the static member variables. I do not
have much code yet, just enough to convince myself that the rest can be
done in a similar fashion (I've attached a file with sketches of the
main classes).
With the current NFIO classes there is one for each FieldContainer that
requires special handling and one (NFIOGeneric) that handles all others.
Global state of the loader is stored in static member variables so that
the individual objects have access to it. Loader objects are created by
NFIOFactory which chooses the proper one from the type name of the
container to load.
The basics will remain quite similar, but there'll be the notion of a
root element that reads/writes the file header, holds the global state
and drives the i/o process. Every i/o object will hold a pointer to the
root element. The i/o objects should be lightweight enough to allow
rapid creation, but maybe the factory will need to be outfitted with a
pool or use a special allocator.
I'm aware this is a quite terse description, but I'll be happy to give
more details if you are interested, so comments, ideas and questions are
very welcome.
Cheers,
Carsten
// Base for elments
class NFIOElementBase
{
public:
virtual void read (const std::string &typeName) = 0;
virtual void postRead( void ) = 0;
virtual void preWrite(const FieldContainerPtr &fc) = 0;
virtual void write (const FieldContainerPtr &fc) = 0;
protected:
struct PtrFieldInfo
{
FieldContainerPtr _fc;
UInt32 _fieldId;
std::vector<UInt32> _ptrIds;
};
private:
FieldContainerPtr _container; // container read by this element
NFIORootElement *_rootElement; // root
UInt16 _version; // version supported by this element
};
// Holds global state for i/o, drives the reading/writing process.
class NFIORootElement : public NFIOElementBase
{
public:
// read file header - trigger reading of FCs in file - fill _elements
virtual void read (const std::string &typeName);
// call postRead for all _elements - afterwards map file ptr ids to real ptrs
virtual void postRead( void );
// count/determine FCs that need to be written - fill _writeFCList
virtual void preWrite(const FieldContainerPtr &fc);
// write out containers
virtual void write (const FieldContainerPtr &fc);
protected:
BinaryReadHandler *_readHandler;
BinaryWriteHandler *_writeHandler;
NFIOOptions _options;
std::list<NFIOElementBase *> _elements;
UInt16 _readHeaderVersion;
std::map <UInt32, UInt32> _readIdMap;
std::list<PtrFieldInfo > _readPtrFields;
std::list<FieldContainerPtr> _writeFCList;
std::set <UInt32 > _writeIdSet;
};
class NFIOCommonElement : public NFIOElementBase
{
// helper methods that are useful for implementing a specific loader
};
// loader for all FCs that do not need special handling
class NFIOGeneric : public NFIOCommonElement
{
public:
virtual void read (const std::string &typeName);
virtual void postRead( void );
virtual void preWrite(const FieldContainerPtr &fc);
virtual void write (const FieldContainerPtr &fc);
};
// Factory singleton for the loader/writer elements - should probably use
// some sort of pool or special purpose allocator to allow rapid creation of
// the objects.
class NFIOFactory
{
// singleton access
static NFIOFactory *the(void);
NFIOElementBase *acquire(const std::string &typeName, NFIORootElement *root);
void release(NFIOElementBase *elem);
};-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Opensg-core mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-core