Commit 0e237fca authored by François Grisez's avatar François Grisez

Remove all calls to 'using namespace' from headers

parent 6fcadc1a
......@@ -6,7 +6,6 @@
#include <map>
#include <memory>
using namespace ::std;
#ifdef _MSC_VER
#ifdef BELR_STATIC
......@@ -24,7 +23,7 @@ using namespace ::std;
namespace belr{
BELR_PUBLIC string tolower(const string &str);
BELR_PUBLIC std::string tolower(const std::string &str);
class ParserContextBase;
......@@ -36,11 +35,11 @@ struct TransitionMap{
bool mPossibleChars[256];
};
class Recognizer : public enable_shared_from_this<Recognizer>{
class Recognizer : public std::enable_shared_from_this<Recognizer>{
public:
void setName(const string &name);
const string &getName()const;
BELR_PUBLIC size_t feed(const shared_ptr<ParserContextBase> &ctx, const string &input, size_t pos);
void setName(const std::string &name);
const std::string &getName()const;
BELR_PUBLIC size_t feed(const std::shared_ptr<ParserContextBase> &ctx, const std::string &input, size_t pos);
unsigned int getId()const{
return mId;
}
......@@ -53,8 +52,8 @@ protected:
virtual bool _getTransitionMap(TransitionMap *mask);
virtual void _optimize(int recursionLevel)=0;
Recognizer();
virtual size_t _feed(const shared_ptr<ParserContextBase> &ctx, const string &input, size_t pos)=0;
string mName;
virtual size_t _feed(const std::shared_ptr<ParserContextBase> &ctx, const std::string &input, size_t pos)=0;
std::string mName;
unsigned int mId;
};
......@@ -63,7 +62,7 @@ public:
CharRecognizer(int to_recognize, bool caseSensitive=false);
private:
virtual void _optimize(int recursionLevel);
virtual size_t _feed(const shared_ptr<ParserContextBase> &ctx, const string &input, size_t pos);
virtual size_t _feed(const std::shared_ptr<ParserContextBase> &ctx, const std::string &input, size_t pos);
int mToRecognize;
bool mCaseSensitive;
};
......@@ -71,13 +70,13 @@ private:
class Selector : public Recognizer{
public:
Selector();
shared_ptr<Selector> addRecognizer(const shared_ptr<Recognizer> &element);
std::shared_ptr<Selector> addRecognizer(const std::shared_ptr<Recognizer> &element);
protected:
virtual void _optimize(int recursionLevel);
virtual size_t _feed(const shared_ptr<ParserContextBase> &ctx, const string &input, size_t pos);
size_t _feedExclusive(const shared_ptr<ParserContextBase> &ctx, const string &input, size_t pos);
virtual size_t _feed(const std::shared_ptr<ParserContextBase> &ctx, const std::string &input, size_t pos);
size_t _feedExclusive(const std::shared_ptr<ParserContextBase> &ctx, const std::string &input, size_t pos);
virtual bool _getTransitionMap(TransitionMap *mask);
list<shared_ptr<Recognizer>> mElements;
std::list<std::shared_ptr<Recognizer>> mElements;
bool mIsExclusive;
};
......@@ -86,41 +85,41 @@ class ExclusiveSelector : public Selector{
public:
ExclusiveSelector();
private:
virtual size_t _feed(const shared_ptr<ParserContextBase> &ctx, const string &input, size_t pos);
virtual size_t _feed(const std::shared_ptr<ParserContextBase> &ctx, const std::string &input, size_t pos);
};
class Sequence : public Recognizer{
public:
Sequence();
shared_ptr<Sequence> addRecognizer(const shared_ptr<Recognizer> &element);
std::shared_ptr<Sequence> addRecognizer(const std::shared_ptr<Recognizer> &element);
virtual bool _getTransitionMap(TransitionMap *mask);
protected:
virtual void _optimize(int recursionLevel);
private:
virtual size_t _feed(const shared_ptr<ParserContextBase> &ctx, const string &input, size_t pos);
list<shared_ptr<Recognizer>> mElements;
virtual size_t _feed(const std::shared_ptr<ParserContextBase> &ctx, const std::string &input, size_t pos);
std::list<std::shared_ptr<Recognizer>> mElements;
};
class Loop : public Recognizer{
public:
Loop();
shared_ptr<Loop> setRecognizer(const shared_ptr<Recognizer> &element, int min=0, int max=-1);
std::shared_ptr<Loop> setRecognizer(const std::shared_ptr<Recognizer> &element, int min=0, int max=-1);
virtual bool _getTransitionMap(TransitionMap *mask);
protected:
virtual void _optimize(int recursionLevel);
private:
virtual size_t _feed(const shared_ptr<ParserContextBase> &ctx, const string &input, size_t pos);
shared_ptr<Recognizer> mRecognizer;
virtual size_t _feed(const std::shared_ptr<ParserContextBase> &ctx, const std::string &input, size_t pos);
std::shared_ptr<Recognizer> mRecognizer;
int mMin, mMax;
};
class Foundation{
public:
static shared_ptr<CharRecognizer> charRecognizer(int character, bool caseSensitive=false);
static shared_ptr<Selector> selector(bool isExclusive=false);
static shared_ptr<Sequence> sequence();
static shared_ptr<Loop> loop();
static std::shared_ptr<CharRecognizer> charRecognizer(int character, bool caseSensitive=false);
static std::shared_ptr<Selector> selector(bool isExclusive=false);
static std::shared_ptr<Sequence> sequence();
static std::shared_ptr<Loop> loop();
};
/*this is an optimization of a selector with multiple individual char recognizer*/
......@@ -129,36 +128,36 @@ public:
CharRange(int begin, int end);
private:
virtual void _optimize(int recursionLevel);
virtual size_t _feed(const shared_ptr<ParserContextBase> &ctx, const string &input, size_t pos);
virtual size_t _feed(const std::shared_ptr<ParserContextBase> &ctx, const std::string &input, size_t pos);
int mBegin,mEnd;
};
class Literal : public Recognizer{
public:
Literal(const string &lit);
Literal(const std::string &lit);
virtual bool _getTransitionMap(TransitionMap *mask);
private:
virtual void _optimize(int recursionLevel);
virtual size_t _feed(const shared_ptr<ParserContextBase> &ctx, const string &input, size_t pos);
string mLiteral;
virtual size_t _feed(const std::shared_ptr<ParserContextBase> &ctx, const std::string &input, size_t pos);
std::string mLiteral;
size_t mLiteralSize;
};
class Utils{
public:
static shared_ptr<Recognizer> literal(const string & lt);
static shared_ptr<Recognizer> char_range(int begin, int end);
static std::shared_ptr<Recognizer> literal(const std::string & lt);
static std::shared_ptr<Recognizer> char_range(int begin, int end);
};
class RecognizerPointer : public Recognizer{
public:
RecognizerPointer();
shared_ptr<Recognizer> getPointed();
void setPointed(const shared_ptr<Recognizer> &r);
std::shared_ptr<Recognizer> getPointed();
void setPointed(const std::shared_ptr<Recognizer> &r);
private:
virtual void _optimize(int recursionLevel);
virtual size_t _feed(const shared_ptr<ParserContextBase> &ctx, const string &input, size_t pos);
shared_ptr<Recognizer> mRecognizer;
virtual size_t _feed(const std::shared_ptr<ParserContextBase> &ctx, const std::string &input, size_t pos);
std::shared_ptr<Recognizer> mRecognizer;
};
/**
......@@ -169,14 +168,14 @@ public:
/**
* Initialize an empty grammar, giving a name for debugging.
**/
BELR_PUBLIC Grammar(const string &name);
BELR_PUBLIC Grammar(const std::string &name);
BELR_PUBLIC ~Grammar();
/**
* Include another grammar into this grammar.
**/
BELR_PUBLIC void include(const shared_ptr<Grammar>& grammar);
BELR_PUBLIC void include(const std::shared_ptr<Grammar>& grammar);
/**
* Add arule to the grammar.
* @param name the name of the rule
......@@ -186,7 +185,7 @@ public:
* TODO: use unique_ptr to enforce this, or make a copy ?
**/
template <typename _recognizerT>
shared_ptr<_recognizerT> addRule(const string & name, const shared_ptr<_recognizerT> &rule){
std::shared_ptr<_recognizerT> addRule(const std::string & name, const std::shared_ptr<_recognizerT> &rule){
assignRule(name, rule);
return rule;
}
......@@ -198,7 +197,7 @@ public:
* @return the rule.
**/
template <typename _recognizerT>
shared_ptr<_recognizerT> extendRule(const string & name, const shared_ptr<_recognizerT> &rule){
std::shared_ptr<_recognizerT> extendRule(const std::string & name, const std::shared_ptr<_recognizerT> &rule){
_extendRule(name, rule);
return rule;
}
......@@ -207,7 +206,7 @@ public:
* @param name the name of the rule
* @return the recognizer implementing this rule. Is NULL if the rule doesn't exist in the grammar.
**/
BELR_PUBLIC shared_ptr<Recognizer> findRule(const string &name);
BELR_PUBLIC std::shared_ptr<Recognizer> findRule(const std::string &name);
/**
* Find a rule from the grammar, given its name.
* Unlike findRule(), getRule() never returns NULL.
......@@ -216,7 +215,7 @@ public:
* @param name the name of the rule to get
* @return the recognizer implementing the rule, or a RecognizerPointer if the rule isn't yet defined.
**/
BELR_PUBLIC shared_ptr<Recognizer> getRule(const string &name);
BELR_PUBLIC std::shared_ptr<Recognizer> getRule(const std::string &name);
/**
* Returns true if the grammar is complete, that is all rules are defined.
* In other words, a grammar is complete if no rule depends on another rule which is not defined.
......@@ -234,11 +233,11 @@ public:
**/
int getNumRules()const;
private:
void assignRule(const string &name, const shared_ptr<Recognizer> &rule);
void _extendRule(const string &name, const shared_ptr<Recognizer> &rule);
map<string,shared_ptr<Recognizer>> mRules;
list<shared_ptr<RecognizerPointer>> mRecognizerPointers;
string mName;
void assignRule(const std::string &name, const std::shared_ptr<Recognizer> &rule);
void _extendRule(const std::string &name, const std::shared_ptr<Recognizer> &rule);
std::map<std::string,std::shared_ptr<Recognizer>> mRules;
std::list<std::shared_ptr<RecognizerPointer>> mRecognizerPointers;
std::string mName;
};
......
......@@ -12,118 +12,118 @@ class ABNFAlternation;
class ABNFBuilder{
public:
virtual ~ABNFBuilder();
virtual shared_ptr<Recognizer> buildRecognizer(const shared_ptr<Grammar> &grammar)=0;
virtual std::shared_ptr<Recognizer> buildRecognizer(const std::shared_ptr<Grammar> &grammar)=0;
};
class ABNFRule : public ABNFBuilder{
public:
ABNFRule();
static shared_ptr<ABNFRule> create();
void setName(const string &name);
void setDefinedAs(const string &defined_as);
void setAlternation(const shared_ptr<ABNFAlternation> &a);
shared_ptr<Recognizer> buildRecognizer(const shared_ptr<Grammar> &grammar);
static std::shared_ptr<ABNFRule> create();
void setName(const std::string &name);
void setDefinedAs(const std::string &defined_as);
void setAlternation(const std::shared_ptr<ABNFAlternation> &a);
std::shared_ptr<Recognizer> buildRecognizer(const std::shared_ptr<Grammar> &grammar);
bool isExtension()const;
const string &getName()const{
const std::string &getName()const{
return mName;
}
private:
shared_ptr<ABNFAlternation> mAlternation;
string mName;
string mDefinedAs;
std::shared_ptr<ABNFAlternation> mAlternation;
std::string mName;
std::string mDefinedAs;
};
class ABNFRuleList : public ABNFBuilder{
public:
static shared_ptr<ABNFRuleList> create();
void addRule(const shared_ptr<ABNFRule> & rule);
shared_ptr<Recognizer> buildRecognizer(const shared_ptr<Grammar> &grammar);
static std::shared_ptr<ABNFRuleList> create();
void addRule(const std::shared_ptr<ABNFRule> & rule);
std::shared_ptr<Recognizer> buildRecognizer(const std::shared_ptr<Grammar> &grammar);
private:
list<shared_ptr<ABNFRule>> mRules;
std::list<std::shared_ptr<ABNFRule>> mRules;
};
class ABNFNumval : public ABNFBuilder{
public:
ABNFNumval();
static shared_ptr<ABNFNumval> create();
shared_ptr<Recognizer> buildRecognizer(const shared_ptr<Grammar> &grammar);
void setDecVal(const string &decval);
void setHexVal(const string &hexval);
void setBinVal(const string &binval);
static std::shared_ptr<ABNFNumval> create();
std::shared_ptr<Recognizer> buildRecognizer(const std::shared_ptr<Grammar> &grammar);
void setDecVal(const std::string &decval);
void setHexVal(const std::string &hexval);
void setBinVal(const std::string &binval);
private:
void parseValues(const string &val, int base);
vector<int> mValues;
void parseValues(const std::string &val, int base);
std::vector<int> mValues;
bool mIsRange;
};
class ABNFElement : public ABNFBuilder{
public:
ABNFElement();
static shared_ptr<ABNFElement> create();
shared_ptr<Recognizer> buildRecognizer(const shared_ptr<Grammar> &grammar);
void setElement(const shared_ptr<ABNFBuilder> &e);
void setRulename(const string &rulename);
void setCharVal(const string &charval);
void setProseVal(const string &prose);
static std::shared_ptr<ABNFElement> create();
std::shared_ptr<Recognizer> buildRecognizer(const std::shared_ptr<Grammar> &grammar);
void setElement(const std::shared_ptr<ABNFBuilder> &e);
void setRulename(const std::string &rulename);
void setCharVal(const std::string &charval);
void setProseVal(const std::string &prose);
private:
shared_ptr<ABNFBuilder> mElement;
string mRulename;
string mCharVal;
std::shared_ptr<ABNFBuilder> mElement;
std::string mRulename;
std::string mCharVal;
};
class ABNFGroup : public ABNFBuilder{
public:
ABNFGroup();
static shared_ptr<ABNFGroup> create();
shared_ptr<Recognizer> buildRecognizer(const shared_ptr<Grammar> &grammar);
void setAlternation(const shared_ptr<ABNFAlternation> &a);
static std::shared_ptr<ABNFGroup> create();
std::shared_ptr<Recognizer> buildRecognizer(const std::shared_ptr<Grammar> &grammar);
void setAlternation(const std::shared_ptr<ABNFAlternation> &a);
private:
shared_ptr<ABNFAlternation> mAlternation;
std::shared_ptr<ABNFAlternation> mAlternation;
};
class ABNFRepetition : public ABNFBuilder{
public:
ABNFRepetition();
static shared_ptr<ABNFRepetition> create();
void setRepeat(const string &r);
static std::shared_ptr<ABNFRepetition> create();
void setRepeat(const std::string &r);
void setMin(int min);
void setMax(int max);
void setCount(int count);
void setElement(const shared_ptr<ABNFElement> &e);
shared_ptr<Recognizer> buildRecognizer(const shared_ptr<Grammar> &grammar);
void setElement(const std::shared_ptr<ABNFElement> &e);
std::shared_ptr<Recognizer> buildRecognizer(const std::shared_ptr<Grammar> &grammar);
private:
int mMin, mMax, mCount;
string mRepeat;
shared_ptr<ABNFElement> mElement;
std::string mRepeat;
std::shared_ptr<ABNFElement> mElement;
};
class ABNFOption : public ABNFBuilder{
public:
ABNFOption();
static shared_ptr<ABNFOption> create();
void setAlternation(const shared_ptr<ABNFAlternation> &a);
shared_ptr<Recognizer> buildRecognizer(const shared_ptr<Grammar> &grammar);
static std::shared_ptr<ABNFOption> create();
void setAlternation(const std::shared_ptr<ABNFAlternation> &a);
std::shared_ptr<Recognizer> buildRecognizer(const std::shared_ptr<Grammar> &grammar);
private:
shared_ptr<ABNFAlternation> mAlternation;
std::shared_ptr<ABNFAlternation> mAlternation;
};
class ABNFConcatenation : public ABNFBuilder{
public:
static shared_ptr<ABNFConcatenation> create();
shared_ptr<Recognizer> buildRecognizer(const shared_ptr<Grammar> &grammar);
void addRepetition(const shared_ptr<ABNFRepetition> &r);
static std::shared_ptr<ABNFConcatenation> create();
std::shared_ptr<Recognizer> buildRecognizer(const std::shared_ptr<Grammar> &grammar);
void addRepetition(const std::shared_ptr<ABNFRepetition> &r);
private:
list<shared_ptr<ABNFRepetition>> mRepetitions;
std::list<std::shared_ptr<ABNFRepetition>> mRepetitions;
};
class ABNFAlternation : public ABNFBuilder{
public:
static shared_ptr<ABNFAlternation> create();
void addConcatenation(const shared_ptr<ABNFConcatenation> &c);
shared_ptr<Recognizer> buildRecognizer(const shared_ptr<Grammar> &grammar);
shared_ptr<Recognizer> buildRecognizerNoOptim(const shared_ptr<Grammar> &grammar);
static std::shared_ptr<ABNFAlternation> create();
void addConcatenation(const std::shared_ptr<ABNFConcatenation> &c);
std::shared_ptr<Recognizer> buildRecognizer(const std::shared_ptr<Grammar> &grammar);
std::shared_ptr<Recognizer> buildRecognizerNoOptim(const std::shared_ptr<Grammar> &grammar);
private:
list<shared_ptr<ABNFConcatenation>> mConcatenations;
std::list<std::shared_ptr<ABNFConcatenation>> mConcatenations;
};
/**
......@@ -145,7 +145,7 @@ public:
* @param grammar an optional grammar to include.
* @return the Grammar object corresponding to the text definition loaded, NULL if an error occured.
**/
BELR_PUBLIC shared_ptr<Grammar> createFromAbnf(const string &abnf, const shared_ptr<Grammar> &grammar=NULL);
BELR_PUBLIC std::shared_ptr<Grammar> createFromAbnf(const std::string &abnf, const std::shared_ptr<Grammar> &grammar=NULL);
/**
* Create a grammar from an ABNF grammar defined in the text file pointed by path.
* An optional Grammar argument corresponding to a grammar to include can be passed.
......@@ -156,9 +156,9 @@ public:
* @param grammar an optional grammar to include.
* @return the Grammar object corresponding to the text definition loaded, NULL if an error occured.
**/
BELR_PUBLIC shared_ptr<Grammar> createFromAbnfFile(const string &path, const shared_ptr<Grammar> &grammar=NULL);
BELR_PUBLIC std::shared_ptr<Grammar> createFromAbnfFile(const std::string &path, const std::shared_ptr<Grammar> &grammar=NULL);
private:
Parser<shared_ptr<ABNFBuilder>> mParser;
Parser<std::shared_ptr<ABNFBuilder>> mParser;
};
}
......
......@@ -5,7 +5,9 @@
//#include <chrono>
#include <ctime>
namespace belr{
using namespace std;
using namespace belr;
template <class T, class U>
T universal_pointer_cast(const shared_ptr<U>& sp){
......@@ -332,5 +334,3 @@ _parserElementT Parser<_parserElementT>::parseInput(const string &rulename, cons
auto ret= pctx->createRootObject(input);
return ret;
}
}
This diff is collapsed.
#include "belr/abnf.hh"
namespace belr{
using namespace std;
using namespace belr;
/*
* CoreRules grammar
......@@ -556,6 +557,3 @@ void ABNFGrammar::hex_val(){
)
);
}
}//end of namespace
......@@ -5,7 +5,10 @@
#include <algorithm>
#include <iostream>
namespace belr{
using namespace std;
using namespace belr;
TransitionMap::TransitionMap(){
for(size_t i=0;i<sizeof(mPossibleChars)/sizeof(bool);++i)
......@@ -40,7 +43,7 @@ void TransitionMap::merge(const TransitionMap* other){
Recognizer::Recognizer() : mId(0) {
}
void Recognizer::setName(const string& name){
void Recognizer::setName(const std::string& name){
static unsigned int id_base=0;
mName=name;
/* every recognizer that is given a name is given also a unique id*/
......@@ -489,10 +492,9 @@ int Grammar::getNumRules() const{
}
string tolower(const string &str){
string belr::tolower(const string &str){
string ret(str);
transform(ret.begin(),ret.end(), ret.begin(), ::tolower);
return ret;
}
}
......@@ -11,7 +11,8 @@
#include <cstring>
#include <cstdlib>
using namespace::belr;
using namespace belr;
using namespace std;
int main(int argc, char *argv[]){
const char *file=NULL,*message_file=NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment