/// \return Returns the ZoneTableHeader for this zone table segment.
virtual isc::util::MemorySegment& getMemorySegment() = 0;
- /// \brief Create a subclass depending on the memory segment model
+ /// \brief Create an instance depending on the memory segment model
///
/// This is a factory method to create a derived ZoneTableSegment
- /// object based on the \c config passed.
+ /// object based on the \c config passed. The method returns a
+ /// dynamically-allocated object. The caller is responsible for
+ /// destroying it with \c ZoneTableSegment::destroy().
///
- /// FIXME: For now, we always return ZoneTableSegmentLocal.
+ /// FIXME: For now, we always return ZoneTableSegmentLocal
+ /// regardless of the passed \c config.
///
/// \param config The configuration based on which a derived object
/// is returned.
/// \return Returns a ZoneTableSegment object
static ZoneTableSegment* create(const isc::data::Element& config);
+
+ /// \brief Destroy a ZoneTableSegment
+ ///
+ /// This method destroys the passed ZoneTableSegment. It must be
+ /// passed a segment previously created by \c
+ /// ZoneTableSegment::create().
+ ///
+ /// \param segment The segment to destroy.
+ static void destroy(ZoneTableSegment* segment);
};
} // namespace memory
TEST(ZoneTableSegment, create) {
const ElementPtr config = Element::fromJSON("{}");
- auto_ptr<ZoneTableSegment>
- seg(ZoneTableSegment::create((*config.get())));
+ ZoneTableSegment* seg = ZoneTableSegment::create((*config.get()));
// By default, a local zone table segment is created.
- EXPECT_NE(static_cast<void*>(NULL), seg.get());
+ EXPECT_NE(static_cast<void*>(NULL), seg);
+
+ ZoneTableSegment::destroy(seg);
}
TEST(ZoneTableSegment, getHeader) {
const ElementPtr config = Element::fromJSON("{}");
- auto_ptr<ZoneTableSegment>
- seg(ZoneTableSegment::create((*config.get())));
+ ZoneTableSegment* seg = ZoneTableSegment::create((*config.get()));
// getHeader() should never return NULL.
ZoneTableHeader* header = seg->getHeader();
// The zone table is unset.
ZoneTable* table = header->getTable();
EXPECT_EQ(static_cast<void*>(NULL), table);
+
+ ZoneTableSegment::destroy(seg);
}
TEST(ZoneTableSegment, getMemorySegment) {
// This doesn't do anything fun except test the API.
const ElementPtr config = Element::fromJSON("{}");
- auto_ptr<ZoneTableSegment>
- seg(ZoneTableSegment::create((*config.get())));
+ ZoneTableSegment* seg = ZoneTableSegment::create((*config.get()));
MemorySegment& mem_sgmt = seg->getMemorySegment();
EXPECT_TRUE(mem_sgmt.allMemoryDeallocated());
+
+ ZoneTableSegment::destroy(seg);
}
} // anonymous namespace