Skip to content
Snippets Groups Projects
Commit 09859b9c authored by ilor's avatar ilor
Browse files

add SentenceContext clone and duplicate

parent 83bbfa4d
No related branches found
No related tags found
No related merge requests found
......@@ -7,4 +7,16 @@ SentenceContext::SentenceContext(const boost::shared_ptr<Corpus2::Sentence>& s)
{
}
SentenceContext SentenceContext::duplicate() const
{
SentenceContext dup(*this);
dup.sentence_.reset(sentence_->clone());
return dup;
}
SentenceContext* SentenceContext::clone() const
{
return new SentenceContext(duplicate());
}
} /* end ns Wccl */
......@@ -9,13 +9,20 @@ namespace Wccl {
/**
* A wrapper for a Corpus2 Sentence that adds a "current position"
* and several convenience functions.
*
* Copying contexts is cheap and safe since the sentence is kept through
* a shared pointer, use duplicate() or clone() to get a copy with a separate
* underlying sentence (which is slower).
*/
class SentenceContext
{
public:
/// Constructor, wraps the Sentence and stes position to 0
/// Constructor, wraps the Sentence and sets position to 0
SentenceContext(const boost::shared_ptr<Corpus2::Sentence>& s);
/// Returns a copy of this with a cloned underlyiong sentence
SentenceContext duplicate() const;
/// Cloning -- clones the underlying sentence as well
SentenceContext* clone() const;
......@@ -97,6 +104,8 @@ private:
int position_;
};
// TODO ConstSentenceContext ?
} /* end ns Wccl */
#endif // LIBWCCL_SENTENCECONTEXT_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment