IPKIFColleague.h
Go to the documentation of this file.00001
00010 #ifndef __IPKIFColleague_H__
00011 #define __IPKIFColleague_H__
00012
00013 #include "PKIFdll.h"
00014 #include <vector>
00015
00016 class IPKIFColleague;
00017 typedef IPKIFColleague IPKIFMediator;
00018 typedef boost::shared_ptr<IPKIFMediator> IPKIFMediatorPtr;
00019 class CPKIFException;
00020
00032 class CAC_API CAC_NO_VTABLE IPKIFColleague
00033 {
00034
00035 public:
00036 virtual void Initialize();
00037 IPKIFColleague();
00038 virtual ~IPKIFColleague();
00039
00040 void AddParent(IPKIFMediator* parent);
00041 void RemoveParent(IPKIFMediator* parent);
00042 bool IsParent(IPKIFMediator*) const;
00043
00044
00045
00046
00047
00048 virtual void InitializeMediator(std::vector<CPKIFException*>* errorInfo = NULL);
00049 virtual void Terminate();
00050
00051 template<class X> X* GetMediator() const;
00052 void AddMediator(IPKIFMediatorPtr& m);
00053
00054
00055 void RemoveMediator(IPKIFMediator*);
00056 void RemoveMediatorAssociations();
00057
00058 template<class X> X* GetMediator(std::vector<const IPKIFColleague *>* tree) const;
00059 void GetMediators(std::vector<IPKIFMediatorPtr>& v) const;
00060
00078 template <class X>
00079 X* FindMediator(const std::vector<IPKIFMediator*>& v, std::vector<const IPKIFColleague *>* tree) const
00080 {
00081 using namespace std;
00082
00083
00084
00085
00086
00087 typename vector<IPKIFMediator*>::const_iterator pos;
00088 const typename vector<IPKIFMediator*>::const_iterator end = v.end();
00089 X* x = NULL;
00090
00091
00092 for(pos = v.begin(); pos != end; ++pos)
00093 {
00094 x = dynamic_cast<X*>(*pos);
00095 if(NULL != x)
00096 return x;
00097 }
00098
00099
00100
00101
00102 for(pos = v.begin(); pos != end; ++pos)
00103 {
00104
00105
00106 const vector<const IPKIFColleague *>::const_iterator treeBegin = tree->begin();
00107 const vector<const IPKIFColleague *>::const_iterator treeEnd = tree->end();
00108
00109
00110 if(treeEnd == find(treeBegin, treeEnd, (*pos)))
00111 {
00112
00113 x = (*pos)->template GetMediatorFromParent<X>(tree);
00114 if(NULL != x)
00115 return x;
00116
00117
00118
00119 x = (*pos)->template GetMediator<X>(tree);
00120 if(NULL != x)
00121 return x;
00122 }
00123 }
00124
00125
00126 return NULL;
00127 }
00128
00146 template <class X>
00147 X* FindMediator(const std::vector<IPKIFMediatorPtr>& v, std::vector<const IPKIFColleague *>* tree) const
00148 {
00149 using namespace std;
00150
00151
00152
00153
00154
00155 typename vector<IPKIFMediatorPtr>::const_iterator pos;
00156 const typename vector<IPKIFMediatorPtr>::const_iterator end = v.end();
00157 X* x = NULL;
00158
00159
00160 for(pos = v.begin(); pos != end; ++pos)
00161 {
00162 x = dynamic_cast<X*>(&(*(*pos)));
00163 if(NULL != x)
00164 return x;
00165 }
00166
00167
00168
00169
00170 for(pos = v.begin(); pos != end; ++pos)
00171 {
00172
00173
00174 const vector<const IPKIFColleague *>::const_iterator treeBegin = tree->begin();
00175 const vector<const IPKIFColleague *>::const_iterator treeEnd = tree->end();
00176
00177
00178 IPKIFMediator * tmpMed = &(*(*pos));
00179 if(treeEnd == find(treeBegin, treeEnd, tmpMed))
00180 {
00181
00182 x = tmpMed->template GetMediatorFromParent<X>(tree);
00183 if(NULL != x)
00184 return x;
00185
00186
00187
00188 x = tmpMed->template GetMediator<X>(tree);
00189 if(NULL != x)
00190 return x;
00191 }
00192 }
00193
00194
00195 return NULL;
00196 }
00197
00198
00199
00200
00209 template<class X> X* GetMediatorFromParent() const
00210 {
00211
00212
00213 std::vector<const IPKIFColleague *> tree;
00214 return GetMediatorFromParent<X>(&tree);
00215 }
00216
00217
00225 template<class X> X* GetMediatorFromParent(std::vector<const IPKIFColleague *>* tree) const
00226 {
00227
00228 tree->push_back(this);
00229 return FindMediator<X>(m_parents, tree);
00230 }
00231
00232 protected:
00233 std::vector<IPKIFMediator*> m_parents;
00234 std::vector<IPKIFMediatorPtr> m_mediators;
00235 private:
00236
00238 IPKIFColleague(const IPKIFColleague& copy);
00240 IPKIFColleague& operator=(const IPKIFColleague& rhs);
00241 };
00242 DECLARE_SMART_POINTERS(IPKIFColleague);
00243
00281 template<class X>
00282 X* IPKIFMediator::GetMediator(
00286 std::vector<const IPKIFColleague *>* tree) const
00287 {
00288 tree->push_back(this);
00289
00290
00291 X* x = FindMediator<X>(m_mediators, tree);
00292 if(NULL != x)
00293 return x;
00294
00295
00296 return GetMediatorFromParent<X>(tree);
00297 }
00335 template<class X>
00336 X* IPKIFMediator::GetMediator() const
00337 {
00338
00339 X* x = NULL;
00340 x = dynamic_cast<X*>(const_cast<IPKIFMediator*>(this));
00341 if(NULL != x)
00342 return x;
00343
00344
00345
00346 std::vector<const IPKIFColleague *> tree;
00347 return GetMediator<X>(&tree);
00348 }
00349
00350 #endif
00351