use assert for getinitflag

This commit is contained in:
wyy 2013-12-11 04:52:33 -08:00
parent acb4150e3c
commit 1e29d25855
5 changed files with 40 additions and 29 deletions

View File

@ -3,6 +3,7 @@
#include <algorithm> #include <algorithm>
#include <set> #include <set>
#include <cassert>
#include "Limonp/logger.hpp" #include "Limonp/logger.hpp"
#include "Trie.hpp" #include "Trie.hpp"
#include "ISegment.hpp" #include "ISegment.hpp"
@ -63,15 +64,16 @@ namespace CppJieba
public: public:
bool cut(Unicode::const_iterator begin, Unicode::const_iterator end, vector<Unicode>& res) const bool cut(Unicode::const_iterator begin, Unicode::const_iterator end, vector<Unicode>& res) const
{ {
assert(_getInitFlag());
#ifndef NO_CODING_LOG #ifndef NO_CODING_LOG
if (!_getInitFlag()) //if (!_getInitFlag())
//{
// LogError("not inited.");
// return false;
//}
if (begin >= end)
{ {
LogError("not inited."); LogError("begin >= end");
return false;
}
if (begin > end)
{
LogError("begin > end");
return false; return false;
} }
#endif #endif

View File

@ -4,6 +4,7 @@
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <memory.h> #include <memory.h>
#include <cassert>
#include "Limonp/str_functs.hpp" #include "Limonp/str_functs.hpp"
#include "Limonp/logger.hpp" #include "Limonp/logger.hpp"
#include "TransCode.hpp" #include "TransCode.hpp"
@ -93,11 +94,12 @@ namespace CppJieba
public: public:
virtual bool cut(Unicode::const_iterator begin, Unicode::const_iterator end, vector<string>& res)const virtual bool cut(Unicode::const_iterator begin, Unicode::const_iterator end, vector<string>& res)const
{ {
if(!_getInitFlag()) //if(!_getInitFlag())
{ //{
LogError("not inited."); // LogError("not inited.");
return false; // return false;
} //}
assert(_getInitFlag());
if(begin == end) if(begin == end)
{ {
return false; return false;

View File

@ -7,6 +7,7 @@
#include <algorithm> #include <algorithm>
#include <set> #include <set>
#include <cassert>
#include "Limonp/logger.hpp" #include "Limonp/logger.hpp"
#include "Trie.hpp" #include "Trie.hpp"
#include "ISegment.hpp" #include "ISegment.hpp"
@ -73,11 +74,13 @@ namespace CppJieba
public: public:
virtual bool cut(Unicode::const_iterator begin, Unicode::const_iterator end, vector<string>& res)const virtual bool cut(Unicode::const_iterator begin, Unicode::const_iterator end, vector<string>& res)const
{ {
if(!_getInitFlag()) //if(!_getInitFlag())
{ //{
LogError("not inited."); // LogError("not inited.");
return false; // return false;
} //}
assert(_getInitFlag());
vector<TrieNodeInfo> segWordInfos; vector<TrieNodeInfo> segWordInfos;
if(!cut(begin, end, segWordInfos)) if(!cut(begin, end, segWordInfos))
{ {

View File

@ -1,6 +1,7 @@
#ifndef CPPJIEBA_MIXSEGMENT_H #ifndef CPPJIEBA_MIXSEGMENT_H
#define CPPJIEBA_MIXSEGMENT_H #define CPPJIEBA_MIXSEGMENT_H
#include <cassert>
#include "MPSegment.hpp" #include "MPSegment.hpp"
#include "HMMSegment.hpp" #include "HMMSegment.hpp"
#include "Limonp/str_functs.hpp" #include "Limonp/str_functs.hpp"
@ -56,11 +57,12 @@ namespace CppJieba
public: public:
virtual bool cut(Unicode::const_iterator begin, Unicode::const_iterator end, vector<string>& res)const virtual bool cut(Unicode::const_iterator begin, Unicode::const_iterator end, vector<string>& res)const
{ {
if(!_getInitFlag()) //if(!_getInitFlag())
{ //{
LogError("not inited."); // LogError("not inited.");
return false; // return false;
} //}
assert(_getInitFlag());
if(begin == end) if(begin == end)
{ {
return false; return false;

View File

@ -3,6 +3,7 @@
#include <algorithm> #include <algorithm>
#include <set> #include <set>
#include <cassert>
#include "Limonp/logger.hpp" #include "Limonp/logger.hpp"
#include "Trie.hpp" #include "Trie.hpp"
#include "ISegment.hpp" #include "ISegment.hpp"
@ -64,15 +65,16 @@ namespace CppJieba
public: public:
bool cut(Unicode::const_iterator begin, Unicode::const_iterator end, vector<Unicode>& res) const bool cut(Unicode::const_iterator begin, Unicode::const_iterator end, vector<Unicode>& res) const
{ {
assert(_getInitFlag());
#ifndef NO_CODING_LOG #ifndef NO_CODING_LOG
if (!_getInitFlag()) //if (!_getInitFlag())
//{
// LogError("not inited.");
// return false;
//}
if (begin >= end)
{ {
LogError("not inited."); LogError("begin >= end");
return false;
}
if (begin > end)
{
LogError("begin > end");
return false; return false;
} }
#endif #endif