summaryrefslogtreecommitdiff
path: root/TAO/tao/Compression
diff options
context:
space:
mode:
authorJohnny Willemsen <jwillemsen@remedy.nl>2012-02-23 08:01:58 +0000
committerJohnny Willemsen <jwillemsen@remedy.nl>2012-02-23 08:01:58 +0000
commita168508bd5ecff93a667483ea7209f70833057bf (patch)
tree6f625cfe463420398ea9e7ad138bf36b13b3fa5c /TAO/tao/Compression
parenta12c723006a4be82d2aa29489b677e9c804acd0d (diff)
downloadATCD-a168508bd5ecff93a667483ea7209f70833057bf.tar.gz
Thu Feb 23 08:00:29 UTC 2012 Johnny Willemsen <jwillemsen@remedy.nl>
* MPC/config/rlecompressor.mpb: * tao/Compression/rle/RLECompressor.cpp: * tao/Compression/rle/RLECompressor.mpc: * tao/Compression/rle/RLECompressor_Factory.cpp: * tao/Compression/rle/TAO_RLECompressor.rc: * tests/Compression/RLECompressorTest.cpp: Updated for the move of the rle compressor to a new ACE library * tao/AnyTypeCode/Any.cpp: * tao/AnyTypeCode/NVList.cpp: Layout changes
Diffstat (limited to 'TAO/tao/Compression')
-rw-r--r--TAO/tao/Compression/rle/RLECompressor.cpp131
-rw-r--r--TAO/tao/Compression/rle/RLECompressor.mpc2
-rw-r--r--TAO/tao/Compression/rle/RLECompressor_Factory.cpp5
-rw-r--r--TAO/tao/Compression/rle/TAO_RLECompressor.rc1
4 files changed, 24 insertions, 115 deletions
diff --git a/TAO/tao/Compression/rle/RLECompressor.cpp b/TAO/tao/Compression/rle/RLECompressor.cpp
index 3f04c38b4c0..47998fbf373 100644
--- a/TAO/tao/Compression/rle/RLECompressor.cpp
+++ b/TAO/tao/Compression/rle/RLECompressor.cpp
@@ -32,11 +32,13 @@
*/
#include "RLECompressor.h"
+#include "ace/Compression/rle/RLECompressor.h"
TAO_BEGIN_VERSIONED_NAMESPACE_DECL
namespace TAO
{
+
RLECompressor::RLECompressor(::Compression::CompressorFactory_ptr compressor_factory)
: BaseCompressor (compressor_factory, 0)
{
@@ -45,94 +47,20 @@ RLECompressor::RLECompressor(::Compression::CompressorFactory_ptr compressor_fac
void
RLECompressor::compress(const ::Compression::Buffer &source, ::Compression::Buffer &target)
{
- size_t in_len = static_cast<size_t>(source.length());
- size_t out_len = static_cast<size_t>((in_len * 1.1) + 32); // Slightly bigger than input
-
- target.length(static_cast< ::CORBA::ULong>(out_len)); // Set a length
-
- const unsigned char *in_p = static_cast<const unsigned char*>(source.get_buffer());
- unsigned char *out_p = static_cast<unsigned char*>(target.get_buffer());
-
- size_t out_index = 0;
- size_t out_base = 0;
- size_t run_count = 0;
- size_t dup_count = 0;
-
- bool run_code = false;
- unsigned char nxt_byte, cur_byte;
-
- if (in_p && out_p) while (in_len-- > 0) {
-
- if (run_code) switch (run_count) {
-
- default:
-
- out_p[out_index = out_base] = ::CORBA::Octet(run_count++ | 0x80);
- out_p[++out_index] = cur_byte = *in_p++;
-
- if (in_len ? cur_byte == (nxt_byte = *in_p) : true) {
- continue;
- }
-
- // Fall Through
-
- case 128:
-
- if (++out_index >= out_len) {
- throw ::Compression::CompressionException();
- } else if (in_len == 0) {
- continue;
- }
+ ACE_UINT64 in_len = source.length();
+ ACE_UINT64 max_len = static_cast<ACE_UINT64>((in_len * 1.1) + 32U); // Slightly bigger than input
- run_code = false;
- out_p[out_base = out_index] = 0;
- dup_count = run_count = 0;
- continue;
- }
+ target.length(static_cast< CORBA::ULong>(max_len)); // Ensure we set a length.
- switch (run_count) {
-
- case 128:
-
- if (++out_index >= out_len) {
- throw ::Compression::CompressionException();
- }
- out_p[out_base = out_index] = 0;
- dup_count = run_count = 0;
-
- // Fall Through
-
- default :
-
- cur_byte = *in_p++;
-
- if (in_len > 0) {
- if (cur_byte == (nxt_byte = *in_p)) {
- if (dup_count++ == 1) {
- if (run_count >= dup_count) {
- out_p[out_base] = static_cast<unsigned char>(run_count - dup_count);
- out_base += run_count;
- }
- run_code = true;
- run_count = dup_count - 1;
- dup_count = 0;
- out_p[out_index = out_base] = static_cast<unsigned char>(run_count++ | 0x80);
- break;
- }
- } else dup_count = 0;
- }
- out_p[out_base] = char(run_count++);
- break;
- }
-
- if (++out_index >= out_len) {
- throw ::Compression::CompressionException();
- }
-
- out_p[out_index] = cur_byte;
+ ACE_UINT64 out_len = ACE_RLECompression::instance()->compress( source.get_buffer(),
+ in_len,
+ target.get_buffer(),
+ max_len );
+ if (ACE_UINT64(-1) == out_len) { // Overrun
+ throw ::Compression::CompressionException();
}
- target.length(++out_index);
+ target.length(static_cast< CORBA::ULong>(out_len)); // Set Output Buffer to the right size now.
// Update statistics for this compressor
this->update_stats(source.length(), target.length());
@@ -141,35 +69,12 @@ RLECompressor::compress(const ::Compression::Buffer &source, ::Compression::Buff
void
RLECompressor::decompress(const ::Compression::Buffer &source, ::Compression::Buffer &target)
{
- size_t in_len = static_cast<size_t>(source.length());
- size_t max_len = static_cast<size_t>(target.length());
-
- size_t out_len = 0;
-
- const unsigned char *in_p = static_cast<const unsigned char*>(source.get_buffer());
- unsigned char *out_p = static_cast<unsigned char*>(target.get_buffer());
-
- if (in_p && out_p) while(in_len--) {
- unsigned char cur_byte = *in_p++;
- size_t cpy_len = size_t((cur_byte & 0x7F) + 1U);
-
- if (cpy_len > max_len) {
- throw ::Compression::CompressionException();
- } else if (cur_byte & 0x80) { // compressed
- if (in_len--) {
- ACE_OS::memset(out_p, *in_p++, cpy_len);
- } else {
- throw ::Compression::CompressionException();
- }
- } else if (in_len >= cpy_len) {
- ACE_OS::memcpy(out_p, in_p, cpy_len); in_p += cpy_len; in_len -= cpy_len;
- } else {
- throw ::Compression::CompressionException();
- }
-
- out_p += cpy_len;
- max_len -= cpy_len;
- out_len += cpy_len;
+ ACE_UINT64 out_len = ACE_RLECompression::instance()->decompress(source.get_buffer(),
+ source.length(),
+ target.get_buffer(),
+ target.length() );
+ if (ACE_UINT64(-1) == out_len) { // Overrun
+ throw ::Compression::CompressionException();
}
target.length(static_cast<CORBA::ULong>(out_len));
diff --git a/TAO/tao/Compression/rle/RLECompressor.mpc b/TAO/tao/Compression/rle/RLECompressor.mpc
index 8577e361d56..784f6c35eff 100644
--- a/TAO/tao/Compression/rle/RLECompressor.mpc
+++ b/TAO/tao/Compression/rle/RLECompressor.mpc
@@ -1,6 +1,6 @@
//$Id$
-project(RLECompressor) : taolib, tao_output, install, compression, taoidldefaults {
+project(RLECompressor) : ace_rlecompressionlib, taolib, tao_output, install, compression, taoidldefaults {
sharedname = TAO_RLECompressor
dynamicflags += TAO_RLECOMPRESSOR_BUILD_DLL
diff --git a/TAO/tao/Compression/rle/RLECompressor_Factory.cpp b/TAO/tao/Compression/rle/RLECompressor_Factory.cpp
index e7cc0a19bd9..7ca12ad6e73 100644
--- a/TAO/tao/Compression/rle/RLECompressor_Factory.cpp
+++ b/TAO/tao/Compression/rle/RLECompressor_Factory.cpp
@@ -17,10 +17,13 @@ Compression::Compressor_ptr
RLE_CompressorFactory::get_compressor(Compression::CompressionLevel)
{
if (::CORBA::is_nil(this->compressor_.in())) {
- this->compressor_ = new ::TAO::RLECompressor(this);
+ ::Compression::Compressor_ptr compressor;
+ ACE_NEW_RETURN( compressor, ::TAO::RLECompressor(this), 0 );
+ this->compressor_ = compressor;
}
return ::Compression::Compressor::_duplicate(this->compressor_.in());
}
}
TAO_END_VERSIONED_NAMESPACE_DECL
+
diff --git a/TAO/tao/Compression/rle/TAO_RLECompressor.rc b/TAO/tao/Compression/rle/TAO_RLECompressor.rc
index 7d04dd8375e..25c1dda6d77 100644
--- a/TAO/tao/Compression/rle/TAO_RLECompressor.rc
+++ b/TAO/tao/Compression/rle/TAO_RLECompressor.rc
@@ -28,3 +28,4 @@ BEGIN
VALUE "Translation", 0x409, 1200
END
END
+