diff options
author | Mark Spruiell <mes@zeroc.com> | 2012-05-08 18:14:39 -0700 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2012-05-08 18:14:39 -0700 |
commit | 7774bb92669779fd165a0510a360fdaecd69f0c3 (patch) | |
tree | 8ea8bba6cac4128cd3e511ff21534db130ff8e49 /cpp/src/Ice/SlicedData.cpp | |
parent | Fixed ICE-4709, batch requests and UnmarshalOutOfBoundsException (diff) | |
download | ice-7774bb92669779fd165a0510a360fdaecd69f0c3.tar.bz2 ice-7774bb92669779fd165a0510a360fdaecd69f0c3.tar.xz ice-7774bb92669779fd165a0510a360fdaecd69f0c3.zip |
* C++ implementation for compact/sliced formats
* C++ implementation for "preserve-slice" metadata
* C++ tests for compact/sliced/preserved types
* Updated stream API
* Python changes for stream API
* Python tests for compact/sliced formats
* Added Ice.Default.SlicedFormat property
Diffstat (limited to 'cpp/src/Ice/SlicedData.cpp')
-rw-r--r-- | cpp/src/Ice/SlicedData.cpp | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/cpp/src/Ice/SlicedData.cpp b/cpp/src/Ice/SlicedData.cpp new file mode 100644 index 00000000000..8633aa309c9 --- /dev/null +++ b/cpp/src/Ice/SlicedData.cpp @@ -0,0 +1,103 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#include <Ice/SlicedData.h> +#include <Ice/Object.h> + +using namespace std; +using namespace Ice; + +IceUtil::Shared* Ice::upCast(SliceInfo* p) { return p; } +IceUtil::Shared* Ice::upCast(SlicedData* p) { return p; } + +Ice::SlicedData::SlicedData(const SliceInfoSeq& seq) : + slices(seq) +{ + // + // Check if any of the preserved slices contain object references. + // + _hasObjects = false; + for(SliceInfoSeq::const_iterator p = seq.begin(); p != seq.end(); ++p) + { + if(!(*p)->objects.empty()) + { + _hasObjects = true; + break; + } + } +} + +void +Ice::SlicedData::clearObjects() +{ + for(SliceInfoSeq::const_iterator p = slices.begin(); p != slices.end(); ++p) + { + // + // Don't just call (*p)->objects.clear(), as releasing references + // to the objects could have unexpected side effects. We exchange + // the vector into a temporary and then let the temporary fall out + // of scope. + // + vector<ObjectPtr> tmp; + tmp.swap((*p)->objects); + } + + _hasObjects = false; +} + +void +Ice::SlicedData::__gcReachable(IceInternal::GCCountMap& m) const +{ + // + // Iterate over the object references in each preserved slice. + // + for(SliceInfoSeq::const_iterator p = slices.begin(); p != slices.end(); ++p) + { + for(vector<ObjectPtr>::const_iterator q = (*p)->objects.begin(); q != (*p)->objects.end(); ++q) + { + (*q)->__addObject(m); + } + } +} + +void +Ice::SlicedData::__gcClear() +{ + // + // Iterate over the object references in each preserved slice. + // + for(SliceInfoSeq::const_iterator p = slices.begin(); p != slices.end(); ++p) + { + for(vector<ObjectPtr>::iterator q = (*p)->objects.begin(); q != (*p)->objects.end(); ++q) + { + if((*q)->__usesGC()) + { + (*q)->__decRefUnsafe(); + (*q).__clearHandleUnsafe(); + } + } + (*p)->objects.clear(); + } + + _hasObjects = false; +} + +void +Ice::SlicedData::__addObject(IceInternal::GCCountMap& m) +{ + IceInternal::GCCountMap::iterator pos = m.find(this); + if(pos == m.end()) + { + m[this] = 1; + } + else + { + ++pos->second; + } +} |