diff options
author | graehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-07-20 00:11:45 +0000 |
---|---|---|
committer | graehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-07-20 00:11:45 +0000 |
commit | f28e6d45671035d39dcfc25070c72f6e120032e1 (patch) | |
tree | d3627fd7c440bae67b81f1578fea9576d4836603 /decoder | |
parent | b6cf365f217bc7b528243071af733d4a251ff77c (diff) |
Score::TimesEquals for vlad-mira, intrusive refcount for Score, shared_ptr compile fixes for decoder progs
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@331 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'decoder')
-rwxr-xr-x | decoder/intrusive_refcount.hpp | 84 | ||||
-rwxr-xr-x | decoder/oracle_bleu.h | 3 |
2 files changed, 86 insertions, 1 deletions
diff --git a/decoder/intrusive_refcount.hpp b/decoder/intrusive_refcount.hpp new file mode 100755 index 00000000..4a4b0187 --- /dev/null +++ b/decoder/intrusive_refcount.hpp @@ -0,0 +1,84 @@ +#ifndef GRAEHL__SHARED__INTRUSIVE_REFCOUNT_HPP +#define GRAEHL__SHARED__INTRUSIVE_REFCOUNT_HPP + +#include <boost/intrusive_ptr.hpp> +#include <boost/noncopyable.hpp> +#include <boost/detail/atomic_count.hpp> +#include <cassert> + +/** usage: + struct mine : public boost::instrusive_refcount<mine> {}; + + boost::intrusive_ptr<mine> p(new mine()); +*/ + +namespace boost { +// note: the free functions need to be in boost namespace, OR namespace of involved type. this is the only way to do it. + +template <class T> +class intrusive_refcount; + +template <class T> +class atomic_intrusive_refcount; + +template<class T> +void intrusive_ptr_add_ref(intrusive_refcount<T>* ptr) +{ + ++(ptr->refs); +} + +template<class T> +void intrusive_ptr_release(intrusive_refcount<T>* ptr) +{ + if (!--(ptr->refs)) delete static_cast<T*>(ptr); +} + + +//WARNING: only 2^32 (unsigned) refs allowed. hope that's ok :) +template<class T> +class intrusive_refcount : boost::noncopyable +{ + protected: +// typedef intrusive_refcount<T> pointed_type; + friend void intrusive_ptr_add_ref<T>(intrusive_refcount<T>* ptr); + friend void intrusive_ptr_release<T>(intrusive_refcount<T>* ptr); +// friend class intrusive_ptr<T>; + + intrusive_refcount(): refs(0) {} + ~intrusive_refcount() { assert(refs==0); } + +private: + unsigned refs; +}; + + +template<class T> +void intrusive_ptr_add_ref(atomic_intrusive_refcount<T>* ptr) +{ + ++(ptr->refs); +} + +template<class T> +void intrusive_ptr_release(atomic_intrusive_refcount<T>* ptr) +{ + if(!--(ptr->refs)) delete static_cast<T*>(ptr); +} + +template<class T> +class atomic_intrusive_refcount : boost::noncopyable +{ + protected: + friend void intrusive_ptr_add_ref<T>(atomic_intrusive_refcount<T>* ptr); + friend void intrusive_ptr_release<T>(atomic_intrusive_refcount<T>* ptr); + + atomic_intrusive_refcount(): refs(0) {} + ~atomic_intrusive_refcount() { assert(refs==0); } + +private: + boost::detail::atomic_count refs; +}; + +} + + +#endif diff --git a/decoder/oracle_bleu.h b/decoder/oracle_bleu.h index 94548c18..2ccace61 100755 --- a/decoder/oracle_bleu.h +++ b/decoder/oracle_bleu.h @@ -231,7 +231,8 @@ struct OracleBleu { void IncludeLastScore(std::ostream *out=0) { double bleu_scale_ = doc_src_length * doc_score->ComputeScore(); - doc_score->PlusEquals(*sentscore, scale_oracle); + doc_score->PlusEquals(*sentscore); + doc_score->TimesEquals(scale_oracle); sentscore.reset(); doc_src_length = (doc_src_length + tmp_src_length) * scale_oracle; if (out) { |