Commit 1b661482 authored by Mukund Sivaraman's avatar Mukund Sivaraman
Browse files

[2497] Introduce a new AbstractRdataFactory::create() that takes a MasterLexer

Also have a default implementation that simply concatenates
all token data into a string and calls the create() variant
which accepts a string.
parent 1051eb47
......@@ -163,6 +163,8 @@ typedef map<RRType, RdataFactoryPtr> GenericRdataFactoryMap;
template <typename T>
class RdataFactory : public AbstractRdataFactory {
public:
using AbstractRdataFactory::create;
virtual RdataPtr create(const string& rdata_str) const
{
return (RdataPtr(new T(rdata_str)));
......
......@@ -24,6 +24,9 @@
#include <exceptions/exceptions.h>
#include <dns/rdata.h>
#include <dns/master_lexer.h>
#include <dns/master_loader.h>
#include <dns/master_loader_callbacks.h>
namespace isc {
namespace dns {
......@@ -82,7 +85,7 @@ public:
/// \name Factory methods for polymorphic creation.
///
//@{
///
/// \brief Create RDATA from a string.
///
/// This method creates from a string an \c Rdata object of specific class
......@@ -91,7 +94,7 @@ public:
/// \param rdata_str A string of textual representation of the \c Rdata.
/// \return An \c RdataPtr object pointing to the created \c Rdata object.
virtual RdataPtr create(const std::string& rdata_str) const = 0;
///
/// \brief Create RDATA from wire-format data.
///
/// This method creates from wire-format binary data an \c Rdata object
......@@ -103,7 +106,7 @@ public:
/// \param rdata_len The length in buffer of the \c Rdata. In bytes.
/// \return An \c RdataPtr object pointing to the created \c Rdata object.
virtual RdataPtr create(isc::util::InputBuffer& buffer, size_t rdata_len) const = 0;
///
/// \brief Create RDATA from another \c Rdata object of the same type.
///
/// This method creates an \c Rdata object of specific class corresponding
......@@ -118,6 +121,29 @@ public:
/// be copied to the created \c Rdata object.
/// \return An \c RdataPtr object pointing to the created \c Rdata object.
virtual RdataPtr create(const rdata::Rdata& source) const = 0;
/// \brief Create RDATA from MasterLexer
virtual RdataPtr create(MasterLexer& lexer, const Name*,
MasterLoader::Options,
MasterLoaderCallbacks&) const {
std::string s;
while (true) {
const MasterLexer::Token& token = lexer.getNextToken();
if (token.getType() == MasterLexer::Token::END_OF_FILE) {
break;
}
if (!s.empty()) {
s += " ";
}
s += token.getString();
}
return (create(s));
}
//@}
};
......
......@@ -104,6 +104,7 @@ TEST_F(RRParamRegistryTest, addError) {
class TestRdataFactory : public AbstractRdataFactory {
public:
using AbstractRdataFactory::create;
virtual RdataPtr create(const string& rdata_str) const
{ return (RdataPtr(new in::A(rdata_str))); }
virtual RdataPtr create(InputBuffer& buffer, size_t rdata_len) const
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment