Created
December 24, 2008 11:06
-
-
Save neel/39656 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef PHPCONSTRUCTIDENTITY_H | |
#define PHPCONSTRUCTIDENTITY_H | |
#include <QStringList> | |
#include <map> | |
#include <algorithm> | |
class PHPConstructIdentity{ | |
public: | |
PHPConstructIdentity(); | |
protected: | |
enum Construct{ | |
Class, | |
Function, | |
Macro | |
}; | |
enum ConstructType{ | |
User, | |
System, | |
PHP, | |
Null | |
}; | |
private: | |
struct Impl; | |
static Impl* dictionary; | |
protected: | |
static QStringList& construct(Construct cns, ConstructType cnsTp); | |
public: | |
//static ConstructType construct(Construct cns, const QString& constructName); | |
}; | |
#endif // PHPCONSTRUCTIDENTITY_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "phpconstructidentity.h" | |
PHPConstructIdentity::PHPConstructIdentity(){ | |
} | |
class PHPConstructIdentity::Impl{ | |
private: | |
struct InternalImpl{ | |
QStringList userClass; | |
QStringList systemClass; | |
QStringList phpClass; | |
QStringList userFunction; | |
QStringList systemFunction; | |
QStringList phpFunction; | |
QStringList userMacro; | |
QStringList systemMacro; | |
QStringList phpMacro; | |
}; | |
InternalImpl* pImpl; | |
private: | |
class ConstructPointer{ | |
private: | |
Construct c; | |
ConstructType t; | |
public: | |
Construct construct(){return c;} | |
ConstructType constructType(){return t;} | |
public: | |
ConstructPointer(Construct cns, ConstructType cnsT):c(cns), t(cnsT){} | |
bool operator==(const ConstructPointer& cnsPt) const{ | |
return (cnsPt.c == c && cnsPt.t == t); | |
} | |
public: | |
struct LessFunction{ | |
bool operator()(const ConstructPointer& lhsCnsPt, const ConstructPointer& rhsCnsPt) const{ | |
return lhsCnsPt.t < rhsCnsPt.t; | |
} | |
}; | |
struct FakeLessFunctor{ | |
bool operator()(const ConstructPointer&, const ConstructPointer&) const{return true;} | |
}; | |
}; | |
public: | |
typedef std::map<ConstructPointer, QStringList*, ConstructPointer::FakeLessFunctor> ConstructMap; | |
private: | |
ConstructMap constructList; | |
public: | |
Impl(){ | |
constructList[ConstructPointer(Class, User)] = &pImpl->userClass; | |
constructList[ConstructPointer(Class, System)] = &pImpl->systemClass; | |
constructList[ConstructPointer(Class, PHP)] = &pImpl->phpClass; | |
constructList[ConstructPointer(Function, User)] = &pImpl->userFunction; | |
constructList[ConstructPointer(Function, System)] = &pImpl->systemFunction; | |
constructList[ConstructPointer(Function, PHP)] = &pImpl->phpFunction; | |
constructList[ConstructPointer(Macro, User)] = &pImpl->userMacro; | |
constructList[ConstructPointer(Macro, System)] = &pImpl->systemMacro; | |
constructList[ConstructPointer(Macro, PHP)] = &pImpl->phpMacro; | |
} | |
/** | |
returns the list of Construct Names of the specified construct and type | |
\internal | |
*/ | |
QStringList& construct(Construct cns, ConstructType cnsTp) const{ | |
ConstructPointer cnsPt(cns, cnsTp); | |
ConstructMap::const_iterator it = constructList.find(cnsPt); | |
static QStringList dummy; | |
if(it != constructList.end()) | |
return *it->second; | |
return dummy; | |
} | |
/** | |
returns the ConstructType (Null or User or System or PHP) or the Construct | |
searches in all three User, System, PHP StringLists and returns System if it gets that in System and same applies to PHP and user too | |
returns Null if not able to find any | |
\internal | |
*/ | |
ConstructType constructType(Construct cns, const QString& constructName){ | |
ConstructType cnsTypes[Null] = { User, System, PHP };//Its Possible To Change the Order of search from Here | |
ConstructType* itr; | |
for(itr = cnsTypes;itr != cnsTypes+Null;itr++){ | |
if(construct(cns, *itr).contains(constructName))return *itr; | |
} | |
return Null; | |
} | |
}; | |
QStringList& PHPConstructIdentity::construct(Construct cns, ConstructType cnsTp){ | |
return dictionary->construct(cns, cnsTp);//Most Probabbly Error Comes from this line | |
} | |
/*ConstructType PHPConstructIdentity::construct(Construct cns, const QString& constructName){ | |
return dictionary->construct(cns, constructName); | |
}*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment