00001 00009 #ifndef __CONTENTWITHATTRIBUTES_H__ 00010 #define __CONTENTWITHATTRIBUTES_H__ 00011 00012 #include "PKIFCMSDLL.h" 00013 #include "IPKIFHasAttributes.h" 00014 #include "OID.h" 00015 #include "ContentType.h" 00016 #include "components.h" 00017 00018 #include <vector> 00019 00020 FD_SMART_PTR(CPKIFContentInfo); 00021 FD_LIST_PTR(CPKIFAttribute); 00022 00028 class PKIFCMS_API CPKIFContentWithAttributes : public IPKIFHasAttributes, public CPKIFContentType 00029 { 00030 public: 00031 CPKIFContentWithAttributes(); 00032 //CPKIFContentWithAttributes(const CPKIFBufferPtr& siBuf); 00033 virtual ~CPKIFContentWithAttributes(); 00034 00035 bool Decoded() const; 00036 00037 CPKIFBufferPtr Encode(); 00038 00039 void Decode(CPKIFBufferPtr& buf); //decodes 00040 00041 void SetContentInfo(CPKIFContentInfoPtr& contentList); 00042 CPKIFContentInfoPtr GetContentInfo() const; 00043 00044 //signed attrs 00045 void GetAttributes(CPKIFAttributeList& sal); 00046 void AddAttribute(CPKIFAttributePtr& sa); 00047 template <class T> boost::shared_ptr<T> GetAttribute(); 00048 00049 // The following 2 functions are declared virtual in "IPKIFHasAttributes" 00050 void GetEncodedAttributes (CPKIFBufferPtr& buf); 00051 00052 00053 // The following functions are a workaround bc it's not wise to use 00054 // static members inside of template functions. This should be revisited 00055 // after a more "correct" approach has been decided. 00056 void _GetAttributes(std::vector<CPKIFAttributePtr>& attrVector); 00057 00058 virtual void GetAddedAttributes(std::vector<CPKIFAttributePtr>& attr); 00059 private: 00061 CPKIFContentWithAttributes(const CPKIFContentWithAttributes& copy); 00063 CPKIFContentWithAttributes& operator=(const CPKIFContentWithAttributes& rhs); //added 4/6/2004 00064 00065 enum {thisComponent=TOOLKIT_MESSAGE_CONTENT_INFO}; 00066 00067 struct CPKIFContentWithAttributesImpl *m_impl; 00068 00069 }; 00070 DECLARE_SMART_POINTERS(CPKIFContentWithAttributes); 00071 typedef std::vector<CPKIFContentWithAttributesPtr, PKIFAlloc<CPKIFContentWithAttributesPtr> > CPKIFContentWithAttributesList; 00072 DECLARE_SMART_POINTERS(CPKIFContentWithAttributesList); 00073 // compatibility typedef for applications 00074 typedef CPKIFContentWithAttributesList CPKIFContentWithAttributess; 00075 DECLARE_SMART_POINTERS(CPKIFContentWithAttributess); 00076 00084 template <class T> boost::shared_ptr<T> CPKIFContentWithAttributes::GetAttribute() 00085 { 00086 //XXX*** Read the comments below and fix this please 00087 00088 std::vector<CPKIFAttributePtr> attrVector; 00089 // The following function is a workaround bc it's not wise to use 00090 // static members inside of template functions. This should be revisited 00091 // after a more "correct" approach has been decided. 00092 _GetAttributes(attrVector); 00093 00094 00095 CPKIFStringPtr oidStr(new std::string(T::extOID)); 00096 CPKIFOID oid(oidStr); 00097 00098 CPKIFAttribute* p = NULL; 00099 std::vector<CPKIFAttributePtr>::iterator pos; 00100 std::vector<CPKIFAttributePtr>::iterator end = attrVector.end(); 00101 for(pos = attrVector.begin(); pos != end; ++pos) 00102 { 00103 p = &(*(*pos)); 00104 if(oid == (*pos)->GetOID() && NULL != dynamic_cast<T*>(p)) 00105 { 00106 return *((boost::shared_ptr<T>*)&(*pos)); 00107 } 00108 } 00109 00110 boost::shared_ptr<T> nullExt; 00111 return nullExt; 00112 } 00113 00114 00115 00116 #endif //__CONTENTWITHATTRIBUTES_H__