validity. */
Packet clone() const; ///< Create copy packet
/**< clone() will create a complete copy of \c this
- packet. The returned packet will have the same data and
- packet chain. It does however not share any data with
- the original packet. */
+ packet. The returned packet will have the same data,
+ annotations and packet chain. It does however not
+ share any data with the original packet. */
// conversion constructors
BOOST_CHECK_EQUAL( p2.annotation<ComplexAnnotation>().s, "dead beef" );
BOOST_CHECK_EQUAL( p2.annotation<ComplexAnnotation>().i, 0x12345678 );
+ senf::Packet pClone (packet.clone());
+
p2.clearAnnotations();
BOOST_CHECK_EQUAL( p2.annotation<ComplexAnnotation>().s, "empty" );
BOOST_CHECK_EQUAL( p2.annotation<ComplexAnnotation>().i, -1 );
BOOST_CHECK_EQUAL( p2.annotation<IntAnnotation>().value, 0 );
+ BOOST_CHECK_EQUAL( pClone.annotation<IntAnnotation>().value, 0xDEADBEEFu );
+ BOOST_CHECK_EQUAL( pClone.annotation<ComplexAnnotation>().s, "dead beef" );
+ BOOST_CHECK_EQUAL( pClone.annotation<ComplexAnnotation>().i, 0x12345678 );
+
BOOST_CHECK( Reg::lookup<IntAnnotation>() >= 0 );
BOOST_CHECK( Reg::lookup<LargeAnnotation>() < 0 );
BOOST_CHECK( Reg::lookup<ComplexAnnotation>() < 0 );
complexAnnotations_.clear();
}
+prefix_ void senf::detail::PacketImpl::assignAnnotations(PacketImpl const & other)
+{
+ std::copy(&other.simpleAnnotations_[0], &other.simpleAnnotations_[0] +
+ sizeof(simpleAnnotations_)/sizeof(simpleAnnotations_[0]), simpleAnnotations_);
+ complexAnnotations_.assign(
+ other.complexAnnotations_.begin(), other.complexAnnotations_.end());
+}
+
prefix_ void * senf::detail::PacketImpl::complexAnnotation(AnnotationRegistry::key_type key)
{
SENF_ASSERT( key < 0, "complexAnnotation called with invalid key");
Annotation & annotation();
void clearAnnotations();
+ void assignAnnotations(PacketImpl const & other);
void dumpAnnotations(std::ostream & os);
/** \brief Internal: Keep PacketImpl instance alive
virtual ~EntryBase() {}
virtual void * get() = 0;
+
+ typedef EntryBase * ptr;
+ virtual ptr clone() const = 0;
};
+ inline AnnotationRegistry::EntryBase::ptr new_clone( AnnotationRegistry::EntryBase const & entry)
+ {
+ return entry.clone();
+ }
+
template <class Annotation>
class AnnotationRegistry::Entry
: public AnnotationRegistry::EntryBase
{ senf::IGNORE(&proxy_); return key_; }
virtual void * get() { return & annotation_; }
+ virtual EntryBase::ptr clone() const { return new Entry<Annotation>( *this); }
private:
Annotation annotation_;
ptr pi (appendClone(p.p,begin(),p.p->begin()));
for (ptr i (next()); i; i = i->next())
i->appendClone(p.p,begin(),p.p->begin());
+ pi->impl().assignAnnotations( impl());
return pi;
}