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