diff options
author | Kenneth Heafield <github@kheafield.com> | 2011-11-18 16:07:41 +0400 |
---|---|---|
committer | Kenneth Heafield <github@kheafield.com> | 2011-11-18 16:07:41 +0400 |
commit | bf78f7a1acbadbab8da23502d96eb382b60a6b6e (patch) | |
tree | b3ca4bb831bf5f8ea6cd53bbadff2749faa8bca4 /OnDiskPt | |
parent | 1192e6f2b045e00fe74060277e7a797a02b53075 (diff) |
Replace assert with CHECK until people learn how to use assert properly
Diffstat (limited to 'OnDiskPt')
-rw-r--r-- | OnDiskPt/src/OnDiskWrapper.cpp | 38 | ||||
-rw-r--r-- | OnDiskPt/src/Phrase.cpp | 6 | ||||
-rw-r--r-- | OnDiskPt/src/PhraseNode.cpp | 22 | ||||
-rw-r--r-- | OnDiskPt/src/SourcePhrase.cpp | 2 | ||||
-rw-r--r-- | OnDiskPt/src/TargetPhrase.cpp | 22 | ||||
-rw-r--r-- | OnDiskPt/src/TargetPhraseCollection.cpp | 2 | ||||
-rw-r--r-- | OnDiskPt/src/Vocab.cpp | 2 | ||||
-rw-r--r-- | OnDiskPt/src/Word.cpp | 2 |
8 files changed, 48 insertions, 48 deletions
diff --git a/OnDiskPt/src/OnDiskWrapper.cpp b/OnDiskPt/src/OnDiskWrapper.cpp index 276f41024..79b0563a8 100644 --- a/OnDiskPt/src/OnDiskWrapper.cpp +++ b/OnDiskPt/src/OnDiskWrapper.cpp @@ -21,7 +21,7 @@ #include <direct.h> #endif #include <sys/stat.h> -#include <cassert> +#include "util/check.hh" #include <string> #include "OnDiskWrapper.h" @@ -56,19 +56,19 @@ bool OnDiskWrapper::BeginLoad(const std::string &filePath) bool OnDiskWrapper::OpenForLoad(const std::string &filePath) { m_fileSource.open((filePath + "/Source.dat").c_str(), ios::in | ios::binary); - assert(m_fileSource.is_open()); + CHECK(m_fileSource.is_open()); m_fileTargetInd.open((filePath + "/TargetInd.dat").c_str(), ios::in | ios::binary); - assert(m_fileTargetInd.is_open()); + CHECK(m_fileTargetInd.is_open()); m_fileTargetColl.open((filePath + "/TargetColl.dat").c_str(), ios::in | ios::binary); - assert(m_fileTargetColl.is_open()); + CHECK(m_fileTargetColl.is_open()); m_fileVocab.open((filePath + "/Vocab.dat").c_str(), ios::in); - assert(m_fileVocab.is_open()); + CHECK(m_fileVocab.is_open()); m_fileMisc.open((filePath + "/Misc.dat").c_str(), ios::in); - assert(m_fileMisc.is_open()); + CHECK(m_fileMisc.is_open()); // set up root node LoadMisc(); @@ -86,7 +86,7 @@ bool OnDiskWrapper::LoadMisc() while(m_fileMisc.getline(line, 100000)) { vector<string> tokens; Moses::Tokenize(tokens, line); - assert(tokens.size() == 2); + CHECK(tokens.size() == 2); const string &key = tokens[0]; m_miscInfo[key] = Moses::Scan<UINT64>(tokens[1]); } @@ -109,33 +109,33 @@ bool OnDiskWrapper::BeginSave(const std::string &filePath #endif m_fileSource.open((filePath + "/Source.dat").c_str(), ios::out | ios::in | ios::binary | ios::ate | ios::trunc); - assert(m_fileSource.is_open()); + CHECK(m_fileSource.is_open()); m_fileTargetInd.open((filePath + "/TargetInd.dat").c_str(), ios::out | ios::binary | ios::ate | ios::trunc); - assert(m_fileTargetInd.is_open()); + CHECK(m_fileTargetInd.is_open()); m_fileTargetColl.open((filePath + "/TargetColl.dat").c_str(), ios::out | ios::binary | ios::ate | ios::trunc); - assert(m_fileTargetColl.is_open()); + CHECK(m_fileTargetColl.is_open()); m_fileVocab.open((filePath + "/Vocab.dat").c_str(), ios::out | ios::ate | ios::trunc); - assert(m_fileVocab.is_open()); + CHECK(m_fileVocab.is_open()); m_fileMisc.open((filePath + "/Misc.dat").c_str(), ios::out | ios::ate | ios::trunc); - assert(m_fileMisc.is_open()); + CHECK(m_fileMisc.is_open()); // offset by 1. 0 offset is reserved char c = 0xff; m_fileSource.write(&c, 1); - assert(1 == m_fileSource.tellp()); + CHECK(1 == m_fileSource.tellp()); m_fileTargetInd.write(&c, 1); - assert(1 == m_fileTargetInd.tellp()); + CHECK(1 == m_fileTargetInd.tellp()); m_fileTargetColl.write(&c, 1); - assert(1 == m_fileTargetColl.tellp()); + CHECK(1 == m_fileTargetColl.tellp()); // set up root node - assert(GetNumCounts() == 1); + CHECK(GetNumCounts() == 1); vector<float> counts(GetNumCounts()); counts[0] = DEFAULT_COUNT; m_rootSourceNode = new PhraseNode(); @@ -147,7 +147,7 @@ bool OnDiskWrapper::BeginSave(const std::string &filePath void OnDiskWrapper::EndSave() { bool ret = m_rootSourceNode->Saved(); - assert(ret); + CHECK(ret); GetVocab().Save(*this); @@ -184,7 +184,7 @@ UINT64 OnDiskWrapper::GetMisc(const std::string &key) const { std::map<std::string, UINT64>::const_iterator iter; iter = m_miscInfo.find(key); - assert(iter != m_miscInfo.end()); + CHECK(iter != m_miscInfo.end()); return iter->second; } @@ -205,7 +205,7 @@ Word *OnDiskWrapper::ConvertFromMoses(Moses::FactorDirection /* direction */ size_t factorType = factorsVec[ind]; const Moses::Factor *factor = origWord.GetFactor(factorType); - assert(factor); + CHECK(factor); string str = factor->GetString(); if (isNonTerminal) { diff --git a/OnDiskPt/src/Phrase.cpp b/OnDiskPt/src/Phrase.cpp index 1b7fb54e3..ce6dc208c 100644 --- a/OnDiskPt/src/Phrase.cpp +++ b/OnDiskPt/src/Phrase.cpp @@ -18,7 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ***********************************************************************/ #include <iostream> -#include <cassert> +#include "util/check.hh" #include "../../moses/src/Util.h" #include "Phrase.h" @@ -49,7 +49,7 @@ void Phrase::AddWord(Word *word) void Phrase::AddWord(Word *word, size_t pos) { - assert(pos < m_words.size()); + CHECK(pos < m_words.size()); m_words.insert(m_words.begin() + pos + 1, word); } @@ -73,7 +73,7 @@ int Phrase::Compare(const Phrase &compare) const } if (ret == 0) { - assert(compare.GetSize() >= GetSize()); + CHECK(compare.GetSize() >= GetSize()); ret = (compare.GetSize() > GetSize()) ? 1 : 0; } return ret; diff --git a/OnDiskPt/src/PhraseNode.cpp b/OnDiskPt/src/PhraseNode.cpp index 8d3849ee5..a479294e5 100644 --- a/OnDiskPt/src/PhraseNode.cpp +++ b/OnDiskPt/src/PhraseNode.cpp @@ -17,7 +17,7 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ***********************************************************************/ -#include <cassert> +#include "util/check.hh" #include "PhraseNode.h" #include "OnDiskWrapper.h" #include "TargetPhraseCollection.h" @@ -55,7 +55,7 @@ PhraseNode::PhraseNode(UINT64 filePos, OnDiskWrapper &onDiskWrapper) std::fstream &file = onDiskWrapper.GetFileSource(); file.seekg(filePos); - assert(filePos == file.tellg()); + CHECK(filePos == file.tellg()); file.read((char*) &m_numChildrenLoad, sizeof(UINT64)); @@ -64,11 +64,11 @@ PhraseNode::PhraseNode(UINT64 filePos, OnDiskWrapper &onDiskWrapper) // go to start of node again file.seekg(filePos); - assert(filePos == file.tellg()); + CHECK(filePos == file.tellg()); // read everything into memory file.read(m_memLoad, memAlloc); - assert(filePos + memAlloc == file.tellg()); + CHECK(filePos + memAlloc == file.tellg()); // get value m_value = ((UINT64*)m_memLoad)[1]; @@ -76,7 +76,7 @@ PhraseNode::PhraseNode(UINT64 filePos, OnDiskWrapper &onDiskWrapper) // get counts float *memFloat = (float*) (m_memLoad + sizeof(UINT64) * 2); - assert(countSize == 1); + CHECK(countSize == 1); m_counts[0] = memFloat[0]; m_memLoadLast = m_memLoad + memAlloc; @@ -85,7 +85,7 @@ PhraseNode::PhraseNode(UINT64 filePos, OnDiskWrapper &onDiskWrapper) PhraseNode::~PhraseNode() { free(m_memLoad); - //assert(m_saved); + //CHECK(m_saved); } float PhraseNode::GetCount(size_t ind) const @@ -95,7 +95,7 @@ float PhraseNode::GetCount(size_t ind) const void PhraseNode::Save(OnDiskWrapper &onDiskWrapper, size_t pos, size_t tableLimit) { - assert(!m_saved); + CHECK(!m_saved); // save this node m_targetPhraseColl.Sort(tableLimit); @@ -116,7 +116,7 @@ void PhraseNode::Save(OnDiskWrapper &onDiskWrapper, size_t pos, size_t tableLimi // count info float *memFloat = (float*) (mem + memUsed); - assert(numCounts == 1); + CHECK(numCounts == 1); memFloat[0] = (m_counts.size() == 0) ? DEFAULT_COUNT : m_counts[0]; // if count = 0, put in very large num to make sure its still used. HACK memUsed += sizeof(float) * numCounts; @@ -142,7 +142,7 @@ void PhraseNode::Save(OnDiskWrapper &onDiskWrapper, size_t pos, size_t tableLimi // save this node //Moses::DebugMem(mem, memAlloc); - assert(memUsed == memAlloc); + CHECK(memUsed == memAlloc); std::fstream &file = onDiskWrapper.GetFileSource(); m_filePos = file.tellp(); @@ -150,7 +150,7 @@ void PhraseNode::Save(OnDiskWrapper &onDiskWrapper, size_t pos, size_t tableLimi file.write(mem, memUsed); UINT64 endPos = file.tellp(); - assert(m_filePos + memUsed == endPos); + CHECK(m_filePos + memUsed == endPos); free(mem); @@ -234,7 +234,7 @@ void PhraseNode::GetChild(Word &wordFound, UINT64 &childFilePos, size_t ind, OnD + childSize * ind; size_t memRead = ReadChild(wordFound, childFilePos, currMem, numFactors); - assert(memRead == childSize); + CHECK(memRead == childSize); } size_t PhraseNode::ReadChild(Word &wordFound, UINT64 &childFilePos, const char *mem, size_t numFactors) const diff --git a/OnDiskPt/src/SourcePhrase.cpp b/OnDiskPt/src/SourcePhrase.cpp index 7c95e5ec4..595748c70 100644 --- a/OnDiskPt/src/SourcePhrase.cpp +++ b/OnDiskPt/src/SourcePhrase.cpp @@ -17,7 +17,7 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ***********************************************************************/ -#include <cassert> +#include "util/check.hh" #include "SourcePhrase.h" namespace OnDiskPt diff --git a/OnDiskPt/src/TargetPhrase.cpp b/OnDiskPt/src/TargetPhrase.cpp index 2b62255e4..7480368e0 100644 --- a/OnDiskPt/src/TargetPhrase.cpp +++ b/OnDiskPt/src/TargetPhrase.cpp @@ -57,13 +57,13 @@ void TargetPhrase::Create1AlignFromString(const std::string &align1Str) { vector<size_t> alignPoints; Moses::Tokenize<size_t>(alignPoints, align1Str, "-"); - assert(alignPoints.size() == 2); + CHECK(alignPoints.size() == 2); m_align.push_back(pair<size_t, size_t>(alignPoints[0], alignPoints[1]) ); } void TargetPhrase::SetScore(float score, size_t ind) { - assert(ind < m_scores.size()); + CHECK(ind < m_scores.size()); m_scores[ind] = score; } @@ -101,7 +101,7 @@ char *TargetPhrase::WriteToMemory(OnDiskWrapper &onDiskWrapper, size_t &memUsed) memUsed += word.WriteToMemory((char*) currPtr); } - assert(memUsed == memNeeded); + CHECK(memUsed == memNeeded); return (char *) mem; } @@ -119,7 +119,7 @@ void TargetPhrase::Save(OnDiskWrapper &onDiskWrapper) file.write(mem, memUsed); UINT64 endPos = file.tellp(); - assert(startPos + memUsed == endPos); + CHECK(startPos + memUsed == endPos); m_filePos = startPos; free(mem); @@ -151,7 +151,7 @@ char *TargetPhrase::WriteOtherInfoToMemory(OnDiskWrapper &onDiskWrapper, size_t memUsed += WriteScoresToMemory(mem + memUsed); //DebugMem(mem, memNeeded); - assert(memNeeded == memUsed); + CHECK(memNeeded == memUsed); return mem; } @@ -203,7 +203,7 @@ Moses::TargetPhrase *TargetPhrase::ConvertToMoses(const std::vector<Moses::Facto // words size_t phraseSize = GetSize(); - assert(phraseSize > 0); // last word is lhs + CHECK(phraseSize > 0); // last word is lhs --phraseSize; for (size_t pos = 0; pos < phraseSize; ++pos) { @@ -232,18 +232,18 @@ Moses::TargetPhrase *TargetPhrase::ConvertToMoses(const std::vector<Moses::Facto UINT64 TargetPhrase::ReadOtherInfoFromFile(UINT64 filePos, std::fstream &fileTPColl) { - assert(filePos == fileTPColl.tellg()); + CHECK(filePos == fileTPColl.tellg()); UINT64 memUsed = 0; fileTPColl.read((char*) &m_filePos, sizeof(UINT64)); memUsed += sizeof(UINT64); - assert(m_filePos != 0); + CHECK(m_filePos != 0); memUsed += ReadAlignFromFile(fileTPColl); - assert((memUsed + filePos) == fileTPColl.tellg()); + CHECK((memUsed + filePos) == fileTPColl.tellg()); memUsed += ReadScoresFromFile(fileTPColl); - assert((memUsed + filePos) == fileTPColl.tellg()); + CHECK((memUsed + filePos) == fileTPColl.tellg()); return memUsed; } @@ -289,7 +289,7 @@ UINT64 TargetPhrase::ReadAlignFromFile(std::fstream &fileTPColl) UINT64 TargetPhrase::ReadScoresFromFile(std::fstream &fileTPColl) { - assert(m_scores.size() > 0); + CHECK(m_scores.size() > 0); UINT64 bytesRead = 0; diff --git a/OnDiskPt/src/TargetPhraseCollection.cpp b/OnDiskPt/src/TargetPhraseCollection.cpp index 910af9ea9..bb9c74364 100644 --- a/OnDiskPt/src/TargetPhraseCollection.cpp +++ b/OnDiskPt/src/TargetPhraseCollection.cpp @@ -107,7 +107,7 @@ void TargetPhraseCollection::Save(OnDiskWrapper &onDiskWrapper) free(mem); UINT64 endPos = file.tellp(); - assert(startPos + memUsed == endPos); + CHECK(startPos + memUsed == endPos); m_filePos = startPos; diff --git a/OnDiskPt/src/Vocab.cpp b/OnDiskPt/src/Vocab.cpp index dd641cbfb..9c0470b32 100644 --- a/OnDiskPt/src/Vocab.cpp +++ b/OnDiskPt/src/Vocab.cpp @@ -36,7 +36,7 @@ bool Vocab::Load(OnDiskWrapper &onDiskWrapper) while(getline(file, line)) { vector<string> tokens; Moses::Tokenize(tokens, line); - assert(tokens.size() == 2); + CHECK(tokens.size() == 2); const string &key = tokens[0]; m_vocabColl[key] = Moses::Scan<UINT64>(tokens[1]); } diff --git a/OnDiskPt/src/Word.cpp b/OnDiskPt/src/Word.cpp index d1aeaf6f9..972f74584 100644 --- a/OnDiskPt/src/Word.cpp +++ b/OnDiskPt/src/Word.cpp @@ -93,7 +93,7 @@ size_t Word::ReadFromFile(std::fstream &file, size_t numFactors) file.read(mem, memAlloc); size_t memUsed = ReadFromMemory(mem, numFactors); - assert(memAlloc == memUsed); + CHECK(memAlloc == memUsed); free(mem); return memUsed; |