GME  13
MgaMetaPointerItem.cpp
Go to the documentation of this file.
00001 
00002 #include "stdafx.h"
00003 #include "MgaMetaPointerItem.h"
00004 #include "MgaMetaBase.h"
00005 
00006 // --------------------------- CMgaMetaPointerItem
00007 STDMETHODIMP CMgaMetaPointerItem::get_Desc(BSTR *p)
00008 {
00009         COMTRY {
00010                 CComBSTR pn;
00011                 COMTHROW( ComGetAttrValue(GetUnknown(), ATTRID_PTRITEMDESC, &pn));
00012                 CComBSTR tn = truncateName( GetUnknown(), pn);
00013                 *p = tn.Detach();
00014         } COMCATCH(;)
00015 }
00016 
00017 bool CMgaMetaPointerItem::CheckToken(CComBstrObj &token, bstr_const_iterator i, bstr_const_iterator &e)
00018 {
00019         // the last character cannot be a space
00020         ASSERT( i != e && *(e-1) != L' ' );
00021 
00022         int len = token.Length();
00023 
00024         // return if token is longer or no token
00025         if( (e - i) < len || len <= 0 )
00026                 return false;
00027 
00028         // return if not equal
00029         if( !std::equal(e - len, e, begin(token)) )
00030                 return false;
00031 
00032         // skip those
00033         e -= len;
00034 
00035         // no more characters
00036         if( i == e )
00037                 return true;
00038 
00039         // the previous character must be a space
00040         if( *(--e) != L' ' )
00041         {
00042                 // set the orginal value
00043                 e += len + 1;
00044 
00045                 return false;
00046         }
00047 
00048         // eat the white spaces
00049         while( i != e && *(e-1) == L' ' )
00050                 --e;
00051 
00052         return true;
00053 }
00054 
00055 bool CMgaMetaPointerItem::CheckPath(CCoreObjectPtr &self, pathitems_type &pathitems, bool global)
00056 {
00057         CComBstrObj bstr;
00058         self.GetStringValue(ATTRID_PTRITEMDESC, PutOut(bstr));
00059 
00060 #ifdef _DEBUG
00061         std::string s;
00062         CopyTo(bstr, s);
00063 
00064         PATH_TRACE("PointerItem \"%s\"", s.c_str());
00065 
00066         pathitems_type::iterator i = pathitems.begin();
00067         pathitems_type::iterator e = pathitems.end();
00068         while( i != e )
00069         {
00070                 CopyTo( (*i).terminal_name, s );
00071                 PATH_TRACE(" (term \"%s\" ", s.c_str());
00072 
00073                 CopyTo( (*i).continual_name, s );
00074                 PATH_TRACE("cont \"%s\") ", s.c_str());
00075 
00076                 ++i;
00077         }
00078 
00079         if( global )
00080                 PATH_TRACE("(global) ");
00081 
00082         PATH_TRACE("returns ");
00083 #endif
00084 
00085         // we will check the lists and path from the back
00086 
00087         // bstr iterators
00088         bstr_const_iterator bi = begin(bstr);
00089         bstr_const_iterator be = end(bstr);
00090 
00091         // eat the white spaces
00092         while( bi != be && *(be-1) == L' ' )
00093                 --be;
00094 
00095         // pathitem iterators
00096         pathitems_type::iterator pi = pathitems.begin();
00097         pathitems_type::iterator pe = pathitems.end();
00098 
00099         while( bi != be && pi != pe )
00100         {
00101                 // get the next pathitem
00102                 --pe;
00103 
00104                 bstr_const_iterator bf = be;
00105                 if( global && CheckToken(pe->terminal_name, bi, be) )
00106                 {
00107                         if( bi == be )
00108                         {
00109                                 PATH_TRACE("true\n");
00110                                 return true;
00111                         }
00112 
00113                         be = bf;
00114                 }
00115                 ASSERT( be == bf );
00116 
00117                 if( !CheckToken(pe->continual_name, bi, be) )
00118                 {
00119                         PATH_TRACE("false\n");
00120                         return false;
00121                 }
00122 
00123                 ASSERT( be < bf );
00124         }
00125 
00126         PATH_TRACE( (!global && bi == be && pi == pe) ? "true\n" : "false\n");
00127         return !global && bi == be && pi == pe;
00128 }