diff options
author | Vincent Richard <[email protected]> | 2013-11-21 21:16:57 +0000 |
---|---|---|
committer | Vincent Richard <[email protected]> | 2013-11-21 21:16:57 +0000 |
commit | f9913fa28a27f23fde2d4956c62cbb2fb2bc2ee8 (patch) | |
tree | 2bdc90e361a8f6e0a81164cf67afec9f78f9b959 /src/text.cpp | |
parent | Per-protocol include files. (diff) | |
download | vmime-f9913fa28a27f23fde2d4956c62cbb2fb2bc2ee8.tar.gz vmime-f9913fa28a27f23fde2d4956c62cbb2fb2bc2ee8.zip |
Boost/C++11 shared pointers.
Diffstat (limited to 'src/text.cpp')
-rw-r--r-- | src/text.cpp | 70 |
1 files changed, 35 insertions, 35 deletions
diff --git a/src/text.cpp b/src/text.cpp index 05353b08..987510c1 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -57,7 +57,7 @@ text::text(const string& t) text::text(const word& w) { - appendWord(vmime::create <word>(w)); + appendWord(make_shared <word>(w)); } @@ -75,7 +75,7 @@ void text::parseImpl string::size_type newPos; - const std::vector <ref <word> > words = word::parseMultiple(ctx, buffer, position, end, &newPos); + const std::vector <shared_ptr <word> > words = word::parseMultiple(ctx, buffer, position, end, &newPos); copy_vector(words, m_words); @@ -100,8 +100,8 @@ void text::copyFrom(const component& other) removeAllWords(); - for (std::vector <ref <word> >::const_iterator i = t.m_words.begin() ; i != t.m_words.end() ; ++i) - m_words.push_back(vmime::create <word>(**i)); + for (std::vector <shared_ptr <word> >::const_iterator i = t.m_words.begin() ; i != t.m_words.end() ; ++i) + m_words.push_back(make_shared <word>(**i)); } @@ -125,8 +125,8 @@ bool text::operator==(const text& t) const { bool equal = true; - std::vector <ref <word> >::const_iterator i = m_words.begin(); - std::vector <ref <word> >::const_iterator j = t.m_words.begin(); + std::vector <shared_ptr <word> >::const_iterator i = m_words.begin(); + std::vector <shared_ptr <word> >::const_iterator j = t.m_words.begin(); for ( ; equal && i != m_words.end() ; ++i, ++j) equal = (**i == **j); @@ -148,26 +148,26 @@ const string text::getConvertedText(const charset& dest, const charsetConverterO { string out; - for (std::vector <ref <word> >::const_iterator i = m_words.begin() ; i != m_words.end() ; ++i) + for (std::vector <shared_ptr <word> >::const_iterator i = m_words.begin() ; i != m_words.end() ; ++i) out += (*i)->getConvertedText(dest, opts); return (out); } -void text::appendWord(ref <word> w) +void text::appendWord(shared_ptr <word> w) { m_words.push_back(w); } -void text::insertWordBefore(const size_t pos, ref <word> w) +void text::insertWordBefore(const size_t pos, shared_ptr <word> w) { m_words.insert(m_words.begin() + pos, w); } -void text::insertWordAfter(const size_t pos, ref <word> w) +void text::insertWordAfter(const size_t pos, shared_ptr <word> w) { m_words.insert(m_words.begin() + pos + 1, w); } @@ -175,7 +175,7 @@ void text::insertWordAfter(const size_t pos, ref <word> w) void text::removeWord(const size_t pos) { - const std::vector <ref <word> >::iterator it = m_words.begin() + pos; + const std::vector <shared_ptr <word> >::iterator it = m_words.begin() + pos; m_words.erase(it); } @@ -199,25 +199,25 @@ bool text::isEmpty() const } -const ref <word> text::getWordAt(const size_t pos) +const shared_ptr <word> text::getWordAt(const size_t pos) { return (m_words[pos]); } -const ref <const word> text::getWordAt(const size_t pos) const +const shared_ptr <const word> text::getWordAt(const size_t pos) const { return (m_words[pos]); } -const std::vector <ref <const word> > text::getWordList() const +const std::vector <shared_ptr <const word> > text::getWordList() const { - std::vector <ref <const word> > list; + std::vector <shared_ptr <const word> > list; list.reserve(m_words.size()); - for (std::vector <ref <word> >::const_iterator it = m_words.begin() ; + for (std::vector <shared_ptr <word> >::const_iterator it = m_words.begin() ; it != m_words.end() ; ++it) { list.push_back(*it); @@ -227,21 +227,21 @@ const std::vector <ref <const word> > text::getWordList() const } -const std::vector <ref <word> > text::getWordList() +const std::vector <shared_ptr <word> > text::getWordList() { return (m_words); } -ref <component> text::clone() const +shared_ptr <component> text::clone() const { - return vmime::create <text>(*this); + return make_shared <text>(*this); } -ref <text> text::newFromString(const string& in, const charset& ch) +shared_ptr <text> text::newFromString(const string& in, const charset& ch) { - ref <text> t = vmime::create <text>(); + shared_ptr <text> t = make_shared <text>(); t->createFromString(in, ch); @@ -272,7 +272,7 @@ void text::createFromString(const string& in, const charset& ch) // If there are "too much" non-ASCII chars, encode everything if (alwaysEncode || asciiPercent < 60) // less than 60% ASCII chars { - appendWord(vmime::create <word>(in, ch)); + appendWord(make_shared <word>(in, ch)); } // Else, only encode words which need it else @@ -296,18 +296,18 @@ void text::createFromString(const string& in, const charset& ch) { // No need to create a new encoded word, just append // the current word to the previous one. - ref <word> w = getWordAt(getWordCount() - 1); + shared_ptr <word> w = getWordAt(getWordCount() - 1); w->getBuffer() += " " + chunk; } else { if (count) { - ref <word> w = getWordAt(getWordCount() - 1); + shared_ptr <word> w = getWordAt(getWordCount() - 1); w->getBuffer() += ' '; } - appendWord(vmime::create <word>(chunk, ch)); + appendWord(make_shared <word>(chunk, ch)); prevIs8bit = true; ++count; @@ -317,12 +317,12 @@ void text::createFromString(const string& in, const charset& ch) { if (count && !prevIs8bit) { - ref <word> w = getWordAt(getWordCount() - 1); + shared_ptr <word> w = getWordAt(getWordCount() - 1); w->getBuffer() += " " + chunk; } else { - appendWord(vmime::create <word> + appendWord(make_shared <word> (chunk, charset(charsets::US_ASCII))); prevIs8bit = false; @@ -368,9 +368,9 @@ void text::encodeAndFold } -ref <text> text::decodeAndUnfold(const string& in) +shared_ptr <text> text::decodeAndUnfold(const string& in) { - ref <text> t = vmime::create <text>(); + shared_ptr <text> t = make_shared <text>(); decodeAndUnfold(parsingContext::getDefaultContext(), in, t.get()); @@ -378,9 +378,9 @@ ref <text> text::decodeAndUnfold(const string& in) } -ref <text> text::decodeAndUnfold(const parsingContext& ctx, const string& in) +shared_ptr <text> text::decodeAndUnfold(const parsingContext& ctx, const string& in) { - ref <text> t = vmime::create <text>(); + shared_ptr <text> t = make_shared <text>(); decodeAndUnfold(ctx, in, t.get()); @@ -400,7 +400,7 @@ text* text::decodeAndUnfold(const parsingContext& ctx, const string& in, text* g out->removeAllWords(); - const std::vector <ref <word> > words = word::parseMultiple(ctx, in, 0, in.length(), NULL); + const std::vector <shared_ptr <word> > words = word::parseMultiple(ctx, in, 0, in.length(), NULL); copy_vector(words, out->m_words); @@ -408,9 +408,9 @@ text* text::decodeAndUnfold(const parsingContext& ctx, const string& in, text* g } -const std::vector <ref <component> > text::getChildComponents() +const std::vector <shared_ptr <component> > text::getChildComponents() { - std::vector <ref <component> > list; + std::vector <shared_ptr <component> > list; copy_vector(m_words, list); @@ -422,7 +422,7 @@ const string text::getWholeBuffer() const { string res; - for (std::vector <ref <word> >::const_iterator it = m_words.begin() ; + for (std::vector <shared_ptr <word> >::const_iterator it = m_words.begin() ; it != m_words.end() ; ++it) { res += (*it)->getBuffer(); |