Wrap the unique_ptr so that dtor is called from the cpp.
This make it unnecessary to include scrapast.hpp in whatever cpp takes ownership of the unique_ptr. Without this tho, the destructor of unique_ptr would force you to include scrapast.
This commit is contained in:
parent
dfd0ec343e
commit
c9db1d8ba3
2 changed files with 31 additions and 3 deletions
|
@ -70,9 +70,9 @@ namespace duck {
|
|||
};
|
||||
} //unnamed namespace
|
||||
|
||||
std::unique_ptr<ScrapNode> parse_scraplang (const std::string& parData) {
|
||||
ScrapNodePtr parse_scraplang (const std::string& parData) {
|
||||
ScrapGrammar<std::string::const_iterator> gramm;
|
||||
std::unique_ptr<ScrapNode> retval(new ScrapNode);
|
||||
ScrapNodePtr retval(new ScrapNode);
|
||||
auto it_start = parData.cbegin();
|
||||
|
||||
qi::phrase_parse(it_start, parData.cend(), gramm, sp::ascii::space, *retval);
|
||||
|
@ -85,4 +85,17 @@ namespace duck {
|
|||
boost::apply_visitor(xpath_vis, parAST);
|
||||
return std::move(retval);
|
||||
}
|
||||
|
||||
ScrapNodePtr::ScrapNodePtr (ScrapNode* parPtr) :
|
||||
m_ptr(parPtr)
|
||||
{
|
||||
}
|
||||
|
||||
ScrapNodePtr::ScrapNodePtr (ScrapNodePtr&& parOther) :
|
||||
m_ptr(std::move(parOther.m_ptr))
|
||||
{
|
||||
}
|
||||
|
||||
ScrapNodePtr::~ScrapNodePtr() noexcept {
|
||||
}
|
||||
} //namespace duck
|
||||
|
|
|
@ -9,7 +9,22 @@ namespace duck {
|
|||
struct ScrapNode;
|
||||
struct element_def;
|
||||
|
||||
std::unique_ptr<ScrapNode> parse_scraplang ( const std::string& parData );
|
||||
class ScrapNodePtr {
|
||||
public:
|
||||
explicit ScrapNodePtr ( ScrapNode* parPtr );
|
||||
ScrapNodePtr ( ScrapNodePtr&& parOther );
|
||||
~ScrapNodePtr ( void ) noexcept;
|
||||
|
||||
ScrapNode& operator* ( void ) { return *m_ptr; }
|
||||
const ScrapNode& operator* ( void ) const { return *m_ptr; }
|
||||
ScrapNode& operator-> ( void ) { return *m_ptr; }
|
||||
const ScrapNode& operator-> ( void ) const { return *m_ptr; }
|
||||
|
||||
private:
|
||||
std::unique_ptr<ScrapNode> m_ptr;
|
||||
};
|
||||
|
||||
ScrapNodePtr parse_scraplang ( const std::string& parData );
|
||||
std::vector<element_def> get_xpath_definitions ( const ScrapNode& parAST );
|
||||
} //namespace duck
|
||||
|
||||
|
|
Loading…
Reference in a new issue