From 1e29d25855491b4b145f82daaf971ebaecb9856c Mon Sep 17 00:00:00 2001 From: wyy Date: Wed, 11 Dec 2013 04:52:33 -0800 Subject: [PATCH] use assert for getinitflag --- src/FullSegment.hpp | 16 +++++++++------- src/HMMSegment.hpp | 12 +++++++----- src/MPSegment.hpp | 13 ++++++++----- src/MixSegment.hpp | 12 +++++++----- src/QuerySegment.hpp | 16 +++++++++------- 5 files changed, 40 insertions(+), 29 deletions(-) diff --git a/src/FullSegment.hpp b/src/FullSegment.hpp index 91c5fdc..d67f2f3 100644 --- a/src/FullSegment.hpp +++ b/src/FullSegment.hpp @@ -3,6 +3,7 @@ #include #include +#include #include "Limonp/logger.hpp" #include "Trie.hpp" #include "ISegment.hpp" @@ -63,15 +64,16 @@ namespace CppJieba public: bool cut(Unicode::const_iterator begin, Unicode::const_iterator end, vector& res) const { + assert(_getInitFlag()); #ifndef NO_CODING_LOG - if (!_getInitFlag()) + //if (!_getInitFlag()) + //{ + // LogError("not inited."); + // return false; + //} + if (begin >= end) { - LogError("not inited."); - return false; - } - if (begin > end) - { - LogError("begin > end"); + LogError("begin >= end"); return false; } #endif diff --git a/src/HMMSegment.hpp b/src/HMMSegment.hpp index c9839a4..6e2b7b7 100644 --- a/src/HMMSegment.hpp +++ b/src/HMMSegment.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "Limonp/str_functs.hpp" #include "Limonp/logger.hpp" #include "TransCode.hpp" @@ -93,11 +94,12 @@ namespace CppJieba public: virtual bool cut(Unicode::const_iterator begin, Unicode::const_iterator end, vector& res)const { - if(!_getInitFlag()) - { - LogError("not inited."); - return false; - } + //if(!_getInitFlag()) + //{ + // LogError("not inited."); + // return false; + //} + assert(_getInitFlag()); if(begin == end) { return false; diff --git a/src/MPSegment.hpp b/src/MPSegment.hpp index 09d10b5..14b8f21 100644 --- a/src/MPSegment.hpp +++ b/src/MPSegment.hpp @@ -7,6 +7,7 @@ #include #include +#include #include "Limonp/logger.hpp" #include "Trie.hpp" #include "ISegment.hpp" @@ -73,11 +74,13 @@ namespace CppJieba public: virtual bool cut(Unicode::const_iterator begin, Unicode::const_iterator end, vector& res)const { - if(!_getInitFlag()) - { - LogError("not inited."); - return false; - } + //if(!_getInitFlag()) + //{ + // LogError("not inited."); + // return false; + //} + assert(_getInitFlag()); + vector segWordInfos; if(!cut(begin, end, segWordInfos)) { diff --git a/src/MixSegment.hpp b/src/MixSegment.hpp index 8914256..5f35031 100644 --- a/src/MixSegment.hpp +++ b/src/MixSegment.hpp @@ -1,6 +1,7 @@ #ifndef CPPJIEBA_MIXSEGMENT_H #define CPPJIEBA_MIXSEGMENT_H +#include #include "MPSegment.hpp" #include "HMMSegment.hpp" #include "Limonp/str_functs.hpp" @@ -56,11 +57,12 @@ namespace CppJieba public: virtual bool cut(Unicode::const_iterator begin, Unicode::const_iterator end, vector& res)const { - if(!_getInitFlag()) - { - LogError("not inited."); - return false; - } + //if(!_getInitFlag()) + //{ + // LogError("not inited."); + // return false; + //} + assert(_getInitFlag()); if(begin == end) { return false; diff --git a/src/QuerySegment.hpp b/src/QuerySegment.hpp index 58cf1a2..4487339 100644 --- a/src/QuerySegment.hpp +++ b/src/QuerySegment.hpp @@ -3,6 +3,7 @@ #include #include +#include #include "Limonp/logger.hpp" #include "Trie.hpp" #include "ISegment.hpp" @@ -64,15 +65,16 @@ namespace CppJieba public: bool cut(Unicode::const_iterator begin, Unicode::const_iterator end, vector& res) const { + assert(_getInitFlag()); #ifndef NO_CODING_LOG - if (!_getInitFlag()) + //if (!_getInitFlag()) + //{ + // LogError("not inited."); + // return false; + //} + if (begin >= end) { - LogError("not inited."); - return false; - } - if (begin > end) - { - LogError("begin > end"); + LogError("begin >= end"); return false; } #endif