Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorHieu Hoang <hieuhoang@gmail.com>2016-01-13 17:57:20 +0300
committerHieu Hoang <hieuhoang@gmail.com>2016-01-13 17:57:20 +0300
commit38f999fa3f8f3f91ae8c898681a00ab6b0fdf539 (patch)
treee98f5456ef875f0f29a04681050475c54ca88325 /util
parent74285a4db3dd346a6127ea5375dd03e78ef743c3 (diff)
parente0fb456dbb3296bb1523d7a48b5f627322e33a4b (diff)
Merge ../mosesdecoder into perf_moses2
Diffstat (limited to 'util')
-rw-r--r--util/CMakeLists.txt68
-rw-r--r--util/exception.cc20
-rw-r--r--util/exception.hh12
-rw-r--r--util/stream/CMakeLists.txt44
-rw-r--r--util/string_stream.hh21
5 files changed, 51 insertions, 114 deletions
diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt
index 6f7f5e99b..8a544aa07 100644
--- a/util/CMakeLists.txt
+++ b/util/CMakeLists.txt
@@ -58,52 +58,24 @@ add_library(kenlm_util OBJECT ${KENLM_UTIL_DOUBLECONVERSION_SOURCE} ${KENLM_UTIL
# Only compile and run unit tests if tests should be run
if(BUILD_TESTING)
- # Explicitly list the Boost test files to be compiled
- set(KENLM_BOOST_TESTS_LIST
- bit_packing_test
- file_piece_test
- joint_sort_test
- multi_intersection_test
- probing_hash_table_test
- read_compressed_test
- sorted_uniform_test
- tokenize_piece_test
- )
-
- # Iterate through the Boost tests list
- foreach(test ${KENLM_BOOST_TESTS_LIST})
-
- # Compile the executable, linking against the requisite dependent object files
- add_executable(${test} ${test}.cc $<TARGET_OBJECTS:kenlm_util>)
-
- # Require the following compile flag
- set_target_properties(${test} PROPERTIES COMPILE_FLAGS -DBOOST_TEST_DYN_LINK)
-
- # Link the executable against boost
- target_link_libraries(${test} ${Boost_LIBRARIES} pthread)
-
- # file_piece_test requires an extra command line parameter
- if ("${test}" STREQUAL "file_piece_test")
- set(test_params
- ${CMAKE_CURRENT_SOURCE_DIR}/file_piece.cc
- )
- else()
- set(test_params
- )
- endif()
-
- # Specify command arguments for how to run each unit test
- #
- # Assuming that foo was defined via add_executable(foo ...),
- # the syntax $<TARGET_FILE:foo> gives the full path to the executable.
- #
- add_test(NAME ${test}_test
- COMMAND $<TARGET_FILE:${test}> ${test_params})
-
- # Group unit tests together
- set_target_properties(${test} PROPERTIES FOLDER "unit_tests")
-
- # End for loop
- endforeach(test)
-
+ # Explicitly list the Boost test files to be compiled
+ set(KENLM_BOOST_TESTS_LIST
+ bit_packing_test
+ joint_sort_test
+ multi_intersection_test
+ probing_hash_table_test
+ read_compressed_test
+ sorted_uniform_test
+ tokenize_piece_test
+ )
+
+ AddTests(TESTS ${KENLM_BOOST_TESTS_LIST}
+ DEPENDS $<TARGET_OBJECTS:kenlm_util>
+ LIBRARIES ${Boost_LIBRARIES} pthread)
+
+ # file_piece_test requires an extra command line parameter
+ KenLMAddTest(TEST file_piece_test
+ DEPENDS $<TARGET_OBJECTS:kenlm_util>
+ LIBRARIES ${Boost_LIBRARIES} pthread
+ TEST_ARGS ${CMAKE_CURRENT_SOURCE_DIR}/file_piece.cc)
endif()
diff --git a/util/exception.cc b/util/exception.cc
index 5ba06f065..01ff9a672 100644
--- a/util/exception.cc
+++ b/util/exception.cc
@@ -24,25 +24,23 @@ void Exception::SetLocation(const char *file, unsigned int line, const char *fun
* them down.
*/
std::string old_text;
- std::swap(old_text, what_);
- StringStream stream;
- stream << what_;
- stream << file << ':' << line;
- if (func) stream << " in " << func << " threw ";
+ what_.swap(old_text);
+ what_ << file << ':' << line;
+ if (func) what_ << " in " << func << " threw ";
if (child_name) {
- stream << child_name;
+ what_ << child_name;
} else {
#ifdef __GXX_RTTI
- stream << typeid(this).name();
+ what_ << typeid(this).name();
#else
- stream << "an exception";
+ what_ << "an exception";
#endif
}
if (condition) {
- stream << " because `" << condition << '\'';
+ what_ << " because `" << condition << '\'';
}
- stream << ".\n";
- stream << old_text;
+ what_ << ".\n";
+ what_ << old_text;
}
namespace {
diff --git a/util/exception.hh b/util/exception.hh
index 00207b242..b30183e7f 100644
--- a/util/exception.hh
+++ b/util/exception.hh
@@ -8,7 +8,7 @@
#include <string>
#include <stdint.h>
-// TODO(hieu) delete this
+// TODO(hieu): delete this
#include <sstream>
namespace util {
@@ -20,7 +20,7 @@ class Exception : public std::exception {
Exception() throw();
virtual ~Exception() throw();
- const char *what() const throw() { return what_.c_str(); }
+ const char *what() const throw() { return what_.str().c_str(); }
// For use by the UTIL_THROW macros.
void SetLocation(
@@ -38,7 +38,7 @@ class Exception : public std::exception {
typedef T Identity;
};
- std::string what_;
+ StringStream what_;
};
/* This implements the normal operator<< for Exception and all its children.
@@ -46,12 +46,10 @@ class Exception : public std::exception {
* boost::enable_if.
*/
template <class Except, class Data> typename Except::template ExceptionTag<Except&>::Identity operator<<(Except &e, const Data &data) {
- // TODO(hieu): change this to
- // StringStream(e.what_) << data;
-
+ // TODO(hieu): delete this.
std::stringstream moses_hack;
moses_hack << data;
- e.what_ += moses_hack.str();
+ e.what_ << moses_hack.str();
return e;
}
diff --git a/util/stream/CMakeLists.txt b/util/stream/CMakeLists.txt
index 3e47f73e6..0c4c115dd 100644
--- a/util/stream/CMakeLists.txt
+++ b/util/stream/CMakeLists.txt
@@ -37,38 +37,14 @@ set(KENLM_UTIL_STREAM_SOURCE
if(BUILD_TESTING)
-
- # Explicitly list the Boost test files to be compiled
- set(KENLM_BOOST_TESTS_LIST
- io_test
- sort_test
- stream_test
- )
-
- # Iterate through the Boost tests list
- foreach(test ${KENLM_BOOST_TESTS_LIST})
-
- # Compile the executable, linking against the requisite dependent object files
- add_executable(${test} ${test}.cc $<TARGET_OBJECTS:kenlm_util>)
-
- # Require the following compile flag
- set_target_properties(${test} PROPERTIES COMPILE_FLAGS -DBOOST_TEST_DYN_LINK)
-
- # Link the executable against boost
- target_link_libraries(${test} ${Boost_LIBRARIES} pthread)
-
- # Specify command arguments for how to run each unit test
- #
- # Assuming that foo was defined via add_executable(foo ...),
- # the syntax $<TARGET_FILE:foo> gives the full path to the executable.
- #
- add_test(NAME ${test}_test
- COMMAND $<TARGET_FILE:${test}>)
-
- # Group unit tests together
- set_target_properties(${test} PROPERTIES FOLDER "unit_tests")
-
- # End for loop
- endforeach(test)
-
+ # Explicitly list the Boost test files to be compiled
+ set(KENLM_BOOST_TESTS_LIST
+ io_test
+ sort_test
+ stream_test
+ )
+
+ AddTests(TESTS ${KENLM_BOOST_TESTS_LIST}
+ DEPENDS $<TARGET_OBJECTS:kenlm_util>
+ LIBRARIES ${Boost_LIBRARIES} pthread)
endif()
diff --git a/util/string_stream.hh b/util/string_stream.hh
index ee76a7a57..28fdd4219 100644
--- a/util/string_stream.hh
+++ b/util/string_stream.hh
@@ -10,14 +10,8 @@ namespace util {
class StringStream : public FakeOStream<StringStream> {
public:
- // Semantics: appends to string. Remember to clear first!
-
- explicit StringStream()
- {}
- /*
- explicit StringStream(std::string &out)
- : out_(out) {}
- */
+ StringStream() {}
+
StringStream &flush() { return *this; }
StringStream &write(const void *data, std::size_t length) {
@@ -25,12 +19,11 @@ class StringStream : public FakeOStream<StringStream> {
return *this;
}
- const std::string &str() const
- { return out_; }
- void str(const std::string &val)
- {
- out_ = val;
- }
+ const std::string &str() const { return out_; }
+
+ void str(const std::string &val) { out_ = val; }
+
+ void swap(std::string &str) { std::swap(out_, str); }
protected:
friend class FakeOStream<StringStream>;