GME  13
MgaFilter.cpp
Go to the documentation of this file.
00001 // MgaFilter.cpp : Implementation of CMgaFilter
00002 #include "stdafx.h"
00003 #include "Mga.h"
00004 #include "MgaFilter.h"
00005 
00007 // CMgaFilter
00008 
00009 #define MAXLEV 30
00010 
00011 void CMgaFilter::init() {
00012         if(newlevel) {
00013                 levels = 0;
00014                 for(OLECHAR *p = wcstok(level, L" "); p; p = wcstok(NULL,L" ")) {
00015                         int low, high, highincr = 0;
00016                         OLECHAR c;
00017                         switch(swscanf(p,L"%u%c%u", &low, &c, &high)) {
00018                         case 0: if(swscanf(p,L"-%u", &high) != 1) COMTHROW(E_MGA_FILTERFORMAT);
00019                                         low = 0;
00020                                         break;
00021                         case 1: high=low;
00022                                         break;
00023                         case 2: 
00024                                         if(c != L'-') COMTHROW(E_MGA_FILTERFORMAT);
00025                                         high= MAXLEV; 
00026                                         highincr =1;
00027                         case 3:
00028                                         if(low > high) COMTHROW(E_MGA_FILTERFORMAT);
00029                         }
00030                         if(high > MAXLEV) COMTHROW(E_MGA_FILTERFORMAT);
00031                         high += highincr;
00032                         unsigned long mask = 1 << low;
00033                         for(int i = low; i <= high; i++) {
00034                                 levels |= mask;
00035                                 mask <<= 1;
00036                         }
00037                 }
00038                 newlevel = false;
00039         }
00040         if(newobjtype) {
00041                 objtypes = 0;
00042                 for(OLECHAR *p = wcstok(objtype, L" "); p; p = wcstok(NULL,L" ")) {
00043                         unsigned int code;
00044                         if(swscanf(p,L"%u", &code) != 1) {
00045                                 const OLECHAR *c[] = {L"OBJTYPE_MODEL", L"OBJTYPE_ATOM", L"OBJTYPE_REFERENCE", L"OBJTYPE_CONNECTION", L"OBJTYPE_SET"};
00046                                 for(code = 0; code < DIM(c); code++) {
00047                                         if(!wcscmp(p,c[code])) break;
00048                                 }
00049                                 code += OBJTYPE_MODEL;  // offset of objtype
00050                         }
00051                         if(code < OBJTYPE_MODEL || code > OBJTYPE_SET) COMTHROW(E_MGA_FILTERFORMAT);
00052                         objtypes |= 1 << code;
00053                 }       
00054                 newobjtype = false;
00055         }
00056         if(newkind) {
00057                 kindnums.clear();
00058                 kindnames.clear();
00059                 wchar_t* kind = this->kind;
00060                 if (kind == NULL)
00061                         kind = L"";
00062                 for(OLECHAR *p = wcstok(kind, L" "); p; p = wcstok(NULL,L" ")) {
00063                         unsigned int code;
00064                         if(swscanf(p,L"#%u", &code) == 1) kindnums.insert(code);
00065                         //else kindnames.insert(CComBSTR(p));// NAMESPACE logic inserted here:
00066                         else {
00067                                 kindnames.insert( CComBSTR(p));
00068                                 kindnames.insert( mgaproject->prefixWNmspc( CComBSTR(p)));
00069                         }
00070                 }       
00071                 newkind = false;
00072         }
00073         if(newrole) {
00074                 rolenums.clear();
00075                 rolenames.clear();
00076                 for(OLECHAR *p = wcstok(role, L" "); p; p = wcstok(NULL,L" ")) {
00077                         unsigned int code;
00078                         if(swscanf(p,L"#%u", &code) == 1) rolenums.insert(code);
00079                         else rolenames.insert(CComBSTR(p));
00080                 }       
00081                 newrole = false;
00082         }
00083         if(newname) {
00084                 names.clear();
00085                 MGA_TRACE("Names at init1");
00086                 for(BSTRhash::iterator i = names.begin(); i!=names.end(); ++i) {
00087                         MGA_TRACE("Names: %ls\n",*i);
00088                 }
00089 
00090                 wchar_t *finish = name + wcslen(name);
00091                 bool inquotes = false;
00092                 wchar_t *begin = name;
00093                 wchar_t *end;
00094                 while (begin < finish) {
00095                         end = wcschr(begin, L'\"');
00096                         if (!end) {
00097                                 end = finish;
00098                         }
00099                         *end = L'\0';
00100                         if (inquotes) {
00101                                 names.insert(CComBSTR(begin));
00102                                 inquotes = false;
00103                         }
00104                         else {
00105                                 for(OLECHAR *p = wcstok(begin, L" "); p; p = wcstok(NULL,L" ")) {
00106                                         names.insert(CComBSTR(p));
00107                                 }       
00108                                 inquotes = true;
00109                         }
00110                         begin = end + 1;
00111                 }
00112 
00113                 MGA_TRACE("Names at init");
00114                 for(BSTRhash::iterator i = names.begin(); i!=names.end(); ++i) {
00115                         MGA_TRACE("Names: %ls\n",*i);
00116                 }
00117                 newname = false;
00118         }
00119 }
00120 
00121 
00122 void CMgaFilter::searchFCOs(CoreObj &self, EXCOLLECTIONTYPE_FOR(MgaFCO) *retcoll, int level) {
00123         bool add = true;
00124         init();
00125         if(self.GetMetaID() == DTID_FOLDER) add = false;
00126         if(add && levels) {
00127                 if((levels & 1 << (level > MAXLEV+1 ? MAXLEV+1: level)) == 0) add = false;
00128         }
00129         if(add && objtypes) {
00130                 if((objtypes & 1 << (GetMetaID(self)-DTID_BASE)) == 0) add =false;
00131         }
00132         if(add && !names.empty()) {
00133                 MGA_TRACE("Names at testbeg");
00134                 for(BSTRhash::iterator i = names.begin(); i!=names.end(); ++i) {
00135                         MGA_TRACE("Names: %ls\n",*i);
00136                 }
00137                 if(names.find(CComBSTR(self[ATTRID_NAME])) == names.end()) add =false;
00138                 MGA_TRACE("Names at testend");
00139                 for(BSTRhash::iterator i = names.begin(); i!=names.end(); ++i) {
00140                         MGA_TRACE("Names: %ls\n",*i);
00141                 }
00142         }
00143         if(add && !(rolenums.empty() && rolenames.empty())) {
00144                 if(self.IsRootFCO()) add = false;
00145                 else {
00146                         long roleref = self[ATTRID_ROLEMETA];
00147                         if(rolenums.find(roleref) == rolenums.end()) {
00148                                 CComBSTR(b);
00149                                 COMTHROW(mgaproject->FindMetaRef(roleref)->get_Name(&b));
00150                                 if(rolenames.find(b) == rolenames.end()) add = false;
00151                         }
00152                 }
00153         }
00154         if(add && !(kindnums.empty() && kindnames.empty())) {
00155                 long kindref = self[ATTRID_META];
00156                 if(kindnums.find(kindref) == kindnums.end()) {
00157                         CComBSTR(b);
00158                         COMTHROW(mgaproject->FindMetaRef(kindref)->get_Name(&b));
00159                         if(kindnames.find(b) == kindnames.end()) add = false;
00160                 }
00161         }
00162         if(add) {
00163                 CComPtr<IMgaFCO> bb;
00164                 ObjForCore(self)->getinterface(&bb);
00165                 retcoll->Add(bb);
00166         }
00167         level += 1;
00168         if((self.GetMetaID() == DTID_MODEL || self.GetMetaID() == DTID_FOLDER) && 
00169                 (!levels || levels & 0xFFFFFFFF << ((level > MAXLEV+1 ? MAXLEV+1: level)))) {
00170                 ITERATE_THROUGH(self[ATTRID_FCOPARENT+ATTRID_COLLECTION]) {
00171                         searchFCOs(ITER, retcoll, level);
00172                 }
00173         }
00174 }
00175 
00176 
00177 
00178 
00179 
00180 
00181 STDMETHODIMP CMgaFilter::get_Name(BSTR *pVal)
00182 {
00183   COMTRY {
00184         CHECK_OUTSTRPAR(pVal);
00185         *pVal = name.Copy();
00186   } COMCATCH(;);
00187 }
00188 
00189 STDMETHODIMP CMgaFilter::put_Name(BSTR newVal)
00190 {
00191   COMTRY {
00192         CHECK_INSTRPAR(newVal);
00193         name = newVal;
00194         newname = true;
00195   } COMCATCH(;);
00196 }
00197 
00198 STDMETHODIMP CMgaFilter::get_Kind(BSTR *pVal)
00199 {
00200   COMTRY {
00201         CHECK_OUTSTRPAR(pVal);
00202         *pVal = kind.Copy();
00203   } COMCATCH(;);
00204 }
00205 
00206 STDMETHODIMP CMgaFilter::put_Kind(BSTR newVal)
00207 {
00208   COMTRY {
00209         CHECK_INSTRPAR(newVal);
00210         kind = newVal;
00211         newkind = true;
00212   } COMCATCH(;);
00213 }
00214 
00215 STDMETHODIMP CMgaFilter::get_Role(BSTR *pVal)
00216 {
00217   COMTRY {
00218         CHECK_OUTSTRPAR(pVal);
00219         *pVal = role.Copy();
00220   } COMCATCH(;);
00221 }
00222 
00223 STDMETHODIMP CMgaFilter::put_Role(BSTR newVal)
00224 {
00225   COMTRY {
00226         CHECK_INSTRPAR(newVal);
00227         role = newVal;
00228         newrole = true;
00229   } COMCATCH(;);
00230 }
00231 
00232 STDMETHODIMP CMgaFilter::get_ObjType(BSTR *pVal)
00233 {
00234   COMTRY {
00235         CHECK_OUTSTRPAR(pVal);
00236         *pVal = objtype.Copy();
00237   } COMCATCH(;);
00238 }
00239 
00240 STDMETHODIMP CMgaFilter::put_ObjType(BSTR newVal)
00241 {
00242   COMTRY {
00243         CHECK_INSTRPAR(newVal);
00244         objtype = newVal;
00245         newobjtype = true;
00246   } COMCATCH(;);
00247 }
00248 
00249 STDMETHODIMP CMgaFilter::get_Level(BSTR *pVal)
00250 {
00251   COMTRY {
00252         CHECK_OUTSTRPAR(pVal);
00253         *pVal = level.Copy();
00254   } COMCATCH(;);
00255 }
00256 
00257 STDMETHODIMP CMgaFilter::put_Level(BSTR newVal)
00258 {
00259   COMTRY {
00260         CHECK_INSTRPAR(newVal);
00261         level = newVal;
00262         newlevel = true;
00263   } COMCATCH(;);
00264 }
00265 
00266 
00267 STDMETHODIMP CMgaFilter::get_Project(IMgaProject **pVal) {
00268   COMTRY {
00269         CHECK_OUTPTRPAR(pVal);
00270         if (!mgaproject)
00271                 throw_com_error(E_MGA_ZOMBIE_NOPROJECT, L"MgaFilter must be created by IMgaProject.CreateFilter, and not CoCreateInstance");
00272         (*pVal = mgaproject)->AddRef();
00273   } COMCATCH(;);
00274 }