00001 #ifndef _APPROX_SERVER_H_
00002 #define _APPROX_SERVER_H_
00003
00004 #include<memory>
00005 #include<vector>
00006 #include<string>
00007 #include<stdexcept>
00008
00009 namespace Approx {
00010
00011 class IApproximator;
00012
00013 class ApproxServer {
00014 public:
00015
00016 struct ApproxEngin {
00017
00018 IApproximator * Self;
00019
00020 virtual ~ApproxEngin() {}
00021
00022 virtual const std::string & GetName() const = 0;
00023
00024 virtual IApproximator* CreateApproximator() = 0;
00025
00026 virtual IApproximator* GetApproximator() = 0;
00027 };
00028
00029
00030 ~ApproxServer() {
00031 vecApproxModule::iterator it = ApproxModules.begin();
00032 while(it != ApproxModules.end()) {
00033 delete *it;
00034 ++it;
00035 }
00036 }
00037
00038
00039 void AddApproxModule(std::auto_ptr<ApproxEngin> AE) {
00040 ApproxModules.push_back(AE.release());
00041 }
00042
00043
00044 inline size_t GetModuleCount() const {
00045 return ApproxModules.size();
00046 }
00047
00048
00049 ApproxEngin & GetModule(const std::string& sModuleName) {
00050 const size_t size = GetModuleCount();
00051 for(size_t i(0);i<size;++i)
00052 if(ApproxModules[i]->GetName() == sModuleName) {
00053 return *ApproxModules[i];
00054 }
00055
00056 throw std::runtime_error(sModuleName);
00057 }
00058
00059 private:
00060
00061 typedef std::vector<ApproxEngin *> vecApproxModule;
00062 vecApproxModule ApproxModules;
00063
00064 };
00065 }
00066
00067 #endif
00068