This repository was archived by the owner on Aug 16, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -62,6 +62,16 @@ TEST(MessageChain_Test, Add_and_Get3) {
6262 ASSERT_STREQ (" Hello" , m.Text ().c_str ());
6363}
6464
65+ TEST (MessageChain_Test, Insert_and_Get) {
66+ using namespace Cyan ;
67+ MessageChain mc;
68+ mc.Add <PlainMessage>(" OOOOOO" );
69+ mc.Insert (mc.begin (), PlainMessage (" Hello" ));
70+ ASSERT_TRUE (mc[0 ]->GetType () == " Plain" );
71+ auto mptr = std::dynamic_pointer_cast<PlainMessage>(mc[0 ]);
72+ ASSERT_STREQ (" Hello" , mptr->Text ().c_str ());
73+ }
74+
6575TEST (MessageChain_Test, GetAll) {
6676 using namespace Cyan ;
6777 MessageChain mc;
Original file line number Diff line number Diff line change @@ -99,6 +99,15 @@ namespace Cyan
9999 return *this ;
100100 }
101101
102+ template <class Iterator , class T >
103+ void Insert (const Iterator& iterator, T&& m)
104+ {
105+ using real_type = typename std::remove_const<typename std::remove_reference<T>::type >::type;
106+ static_assert (std::is_base_of<IMessage, real_type>::value, " 只能接受 IMessage 的派生类" );
107+ std::shared_ptr<IMessage> m_ptr (new real_type (std::forward<T>(m)));
108+ messages_.insert (iterator, std::move (m_ptr));
109+ }
110+
102111 template <class T >
103112 void Remove (const T& m)
104113 {
You can’t perform that action at this time.
0 commit comments