DescriptionScheme.cxx
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "DescriptionScheme.hxx"
00023 #include "XMLAdapter.hxx"
00024
00025 namespace CLAM
00026 {
00027 DescriptionScheme::~DescriptionScheme()
00028 {
00029 Scopes::iterator it = _scopes.begin();
00030 Scopes::iterator end = _scopes.end();
00031 for (; it!=end; it++)
00032 delete *it;
00033 }
00034 namespace Hidden
00035 {
00036 class AttributeInserter : public Component
00037 {
00038 public:
00039 AttributeInserter(DescriptionScheme & scheme) : _scheme(scheme) {}
00040 const char * GetClassName() const {return "AttributeInserter"; }
00041 void StoreOn(Storage & storage) const
00042 {
00043 }
00044 void LoadFrom(Storage & storage)
00045 {
00046 std::string _name;
00047 XMLAdapter<std::string> nameAdapter(_name, "name", false);
00048 storage.Load(nameAdapter);
00049
00050 std::string _scope;
00051 XMLAdapter<std::string> scopeAdapter(_scope, "scope", false);
00052 storage.Load(scopeAdapter);
00053
00054 std::string _type;
00055 XMLAdapter<std::string> typeAdapter(_type, "type", false);
00056 storage.Load(typeAdapter);
00057
00058 if (_type == "Float")
00059 _scheme.AddAttribute<float>(_scope, _name);
00060 else if (_type == "String")
00061 _scheme.AddAttribute<std::string>(_scope, _name);
00062 }
00063 private:
00064 DescriptionScheme & _scheme;
00065 };
00066 }
00067
00068 void DescriptionScheme::StoreOn(Storage & storage) const
00069 {
00070 for (unsigned int i = 0; i < GetNScopes(); i++)
00071 {
00072 const DescriptionScope & scope = GetScope(i);
00073 for (unsigned int j = 0; j < scope.GetNAttributes(); j++)
00074 {
00075 XMLComponentAdapter adapter(scope.GetAttribute(j), "Attribute", true);
00076 storage.Store(adapter);
00077 }
00078 }
00079 }
00080
00081 void DescriptionScheme::LoadFrom(Storage & storage)
00082 {
00083 for (; true; )
00084 {
00085 Hidden::AttributeInserter inserter(*this);
00086 XMLComponentAdapter adapter(inserter, "Attribute", true);
00087 if (!storage.Load(adapter)) break;
00088 }
00089 }
00090 }
00091
00092