Advertisement
zamotivator

Untitled

Aug 2nd, 2012
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. class BitmapTileReplicator : boost::noncopyable
  2. {
  3. private:
  4. RLEPayload::iterator _source;
  5. RLEPayload::append_iterator _result;
  6. position_t _current;
  7. position_t _left;
  8.  
  9. Value _trueValue;
  10. Value _falseValue;
  11.  
  12. void fill(position_t count, bool data)
  13. {
  14. if (data) {
  15. _result.add(_trueValue, static_cast<uint64_t>(count));
  16. } else {
  17. _result.add(_falseValue, static_cast<uint64_t>(count));
  18. }
  19. }
  20.  
  21. public:
  22. BitmapTileReplicator(ConstRLEPayload const* sourceTile,
  23. position_t sourceStartPosition,
  24. position_t sourceExpectedSize,
  25. Value& result) :
  26. _source(sourceTile),
  27. _result(result.getTile(TID_BOOL)),
  28. _current(sourceStartPosition),
  29. _left(sourceExpectedSize)
  30. {
  31. if (sourceTile->count() !=
  32. static_cast<size_t>(sourceExpectedSize)) {
  33. std::ostringstream message;
  34. message << "BitmapTileReplicator::ctor expected size is " <<
  35. sourceExpectedSize <<
  36. " actual size is " <<
  37. sourceTile->count();
  38. throw USER_EXCEPTION(
  39. SCIDB_SE_EXECUTION,
  40. SCIDB_LE_OPERATION_FAILED) << message.str();
  41. }
  42. _trueValue.setBool(true);
  43. _falseValue.setBool(false);
  44. }
  45.  
  46. virtual ~BitmapTileReplicator()
  47. {
  48. _result.flush();
  49. }
  50.  
  51. position_t position() const
  52. {
  53. return _current;
  54. }
  55.  
  56. position_t length() const
  57. {
  58. return _left;
  59. }
  60.  
  61. void skip(position_t count)
  62. {
  63. if (_left < count) {
  64. std::ostringstream message;
  65. message << "BitmapTileReplicator::skip reqiested " <<
  66. count <<
  67. " available " <<
  68. _left;
  69. throw USER_EXCEPTION(
  70. SCIDB_SE_EXECUTION,
  71. SCIDB_LE_OPERATION_FAILED) << message.str();
  72. }
  73. _source += count;
  74. fill(count, false);
  75. _current += count;
  76. _left -= count;
  77. }
  78.  
  79. void copy(position_t count)
  80. {
  81. if (_left < count) {
  82. std::ostringstream message;
  83. message << "BitmapTileReplicator::copy reqiested " <<
  84. count <<
  85. " available " <<
  86. _left;
  87. throw USER_EXCEPTION(
  88. SCIDB_SE_EXECUTION,
  89. SCIDB_LE_OPERATION_FAILED) << message.str();
  90. }
  91. while(count > 0) {
  92. SCIDB_ASSERT(!_source.end());
  93. uint64_t current = min(_source.getRepeatCount(),
  94. static_cast<uint64_t>(count));
  95. SCIDB_ASSERT(current > 0);
  96. fill(current, _source.checkBit());
  97. _source += current;
  98. _current += current;
  99. _left -= current;
  100. count -= current;
  101. }
  102. }
  103. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement