00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <base/Serializable>
00026
00027 using base::Serializable;
00028
00029
00030 Serializable::DerivedClassMap Serializable::derivedClasses;
00031
00032
00033 void Serializable::registerSerializableInstantiator(const String& baseClassTypeName,
00034 const String& derivedClassTypeName,
00035 const SerializableInstantiator& instantiator)
00036 {
00037
00038 DerivedClassMap::iterator derivedClassIter(derivedClasses.find(derivedClassTypeName));
00039
00040
00041 if (derivedClassIter != derivedClasses.end()) {
00042 std::pair<const String, BaseAndInstantiatorPair>& p(*derivedClassIter);
00043 if (p.second.first != baseClassTypeName)
00044 throw std::invalid_argument(Exception(String("Class ")+derivedClassTypeName+" is already registered with a base class of "+baseClassTypeName+"."));
00045 p.second.second = &instantiator;
00046 }
00047 else
00048 derivedClasses[derivedClassTypeName] = BaseAndInstantiatorPair(baseClassTypeName, &instantiator);
00049 }
00050
00051
00052 const Serializable::SerializableInstantiator& Serializable::getSerializableInstantiator(const String& baseClassTypeName,
00053 const String& derivedClassTypeName)
00054 {
00055 DerivedClassMap::iterator derivedClassIter(derivedClasses.find(derivedClassTypeName));
00056 if (derivedClassIter == derivedClasses.end())
00057 throw std::invalid_argument(Exception(String("Class ")+derivedClassTypeName+" not registered."));
00058
00059 if (!baseClassTypeName.empty())
00060 if (derivedClassIter->second.first != baseClassTypeName)
00061 throw std::invalid_argument(Exception(String("Class ")+derivedClassTypeName+" was registered with base class "
00062 +(derivedClassIter->second.first)+" not "+baseClassTypeName));
00063 return *derivedClassIter->second.second;
00064 }
00065