Joshua
open source statistical hierarchical phrase-based machine translation system
|
00001 #ifndef UTIL_STREAM_BLOCK_H 00002 #define UTIL_STREAM_BLOCK_H 00003 00004 #include <cstddef> 00005 #include <stdint.h> 00006 00007 namespace util { 00008 namespace stream { 00009 00013 class Block { 00014 public: 00015 00019 Block() : mem_(NULL), valid_size_(0) {} 00020 00027 Block(void *mem, std::size_t size) : mem_(mem), valid_size_(size) {} 00028 00034 void SetValidSize(std::size_t to) { valid_size_ = to; } 00035 00040 std::size_t ValidSize() const { return valid_size_; } 00041 00043 void *Get() { return mem_; } 00044 00046 const void *Get() const { return mem_; } 00047 00048 00053 const void *ValidEnd() const { 00054 return reinterpret_cast<const uint8_t*>(mem_) + valid_size_; 00055 } 00056 00064 operator bool() const { return mem_ != NULL; } 00065 00071 bool operator!() const { return mem_ == NULL; } 00072 00073 private: 00074 friend class Link; 00075 friend class RewindableStream; 00076 00082 void SetToPoison() { 00083 mem_ = NULL; 00084 } 00085 00086 void *mem_; 00087 std::size_t valid_size_; 00088 }; 00089 00090 } // namespace stream 00091 } // namespace util 00092 00093 #endif // UTIL_STREAM_BLOCK_H