GME  13
CoreMetaObject.cpp
Go to the documentation of this file.
00001 
00002 #include "stdafx.h"
00003 
00004 #include "CoreMetaProject.h"
00005 #include "CoreMetaObject.h"
00006 #include "CoreMetaAttribute.h"
00007 #include "CommonCollection.h"
00008 
00009 // --------------------------- CCoreMetaObject
00010 
00011 CCoreMetaObject::CCoreMetaObject()
00012 {
00013 
00014 }
00015 
00016 CCoreMetaObject::~CCoreMetaObject()
00017 {
00018 
00019         while( !attributes.empty() )
00020         {
00021                 delete attributes.front();
00022                 attributes.pop_front();
00023         }
00024 }
00025 
00026 // ------- COM methods
00027 
00028 STDMETHODIMP CCoreMetaObject::get_Project(ICoreMetaProject **p)
00029 {
00030         CHECK_OUT(p);
00031 
00032         ASSERT( project != NULL );
00033         CopyTo(project, p);
00034         return S_OK;
00035 }
00036 
00037 STDMETHODIMP CCoreMetaObject::get_MetaID(metaid_type *p)
00038 {
00039         CHECK_OUT(p);
00040 
00041         ASSERT( metaid > 0 );
00042         *p = metaid;
00043         return S_OK;
00044 }
00045 
00046 STDMETHODIMP CCoreMetaObject::get_Token(BSTR *p)
00047 {
00048         CHECK_OUT(p);
00049 
00050         CopyTo(token, p);
00051         return S_OK;
00052 }
00053 
00054 STDMETHODIMP CCoreMetaObject::get_Name(BSTR *p)
00055 {
00056         CHECK_OUT(p);
00057 
00058         CopyTo(name, p);
00059         return S_OK;
00060 }
00061 
00062 STDMETHODIMP CCoreMetaObject::get_Attribute(attrid_type attrid, ICoreMetaAttribute **p)
00063 {
00064         CHECK_OUT(p);
00065 
00066         attributes_type::iterator i = attributes.begin();
00067         attributes_type::iterator e = attributes.end();
00068 
00069         while( i != e )
00070         {
00071                 CCoreMetaAttribute *o = *i;
00072                 ++i;
00073 
00074                 ASSERT( o != NULL );
00075                 if( o->attrid == attrid )
00076                 {
00077                         CopyTo(o, p);
00078                         return S_OK;
00079                 }
00080         }
00081         *p = NULL;
00082         return S_OK;
00083 }
00084 
00085 STDMETHODIMP CCoreMetaObject::get_Attributes(ICoreMetaAttributes **p)
00086 {
00087         CHECK_OUT(p);
00088 
00089         COMTRY
00090         {
00091                 typedef CCoreCollection<ICoreMetaAttributes, std::vector<ICoreMetaAttribute*>,
00092                         ICoreMetaAttribute, CCoreMetaAttribute> COMTYPE;
00093 
00094                 CComObjPtr<COMTYPE> q;
00095                 CreateComObject(q);
00096 
00097                 q->Fill(attributes.begin(), attributes.end());
00098                 MoveTo(q, p);
00099         }
00100         COMCATCH(;)
00101 }
00102 
00103 STDMETHODIMP CCoreMetaObject::get_ClassIDs(SAFEARRAY **p)
00104 {
00105         CHECK_OUT(p);
00106 
00107         COMTRY
00108         {
00109                 CopyTo(classids, p);
00110         }
00111         COMCATCH(;)
00112 }
00113 
00114 STDMETHODIMP CCoreMetaObject::AddAttribute(attrid_type attrid, BSTR token, BSTR name, 
00115         valtype_type valtype, ICoreMetaAttribute **p)
00116 {
00117         COMTRY
00118         {
00119                 CComObjPtr<CCoreMetaAttribute> q;
00120                 CreateComPartObject(CastToUnknown(project), q);
00121 
00122                 q->object = this;
00123                 q->attrid = attrid;
00124                 q->token = token;
00125                 q->name = name;
00126                 q->valtype = valtype;
00127         
00128                 attributes.push_front(q);
00129 
00130                 if( p != NULL )
00131                         MoveTo(q, p);
00132         }
00133         COMCATCH(;)
00134 }
00135 
00136 STDMETHODIMP CCoreMetaObject::AddClassID(guid_type classid)
00137 {
00138         COMTRY
00139         {
00140                 GUID null_classid; memset( &null_classid, 0, sizeof( null_classid));
00141                 classids.push_back(null_classid);
00142                 try
00143                 {
00144                         CopyTo(classid, classids.back());
00145                 }
00146                 catch(...)
00147                 {
00148                         classids.pop_back();
00149                         throw;
00150                 }
00151         }
00152         COMCATCH(;)
00153 }