This repository was archived by the owner on Aug 16, 2024. It is now read-only.
File tree 2 files changed +19
-0
lines changed
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) {
62
62
ASSERT_STREQ (" Hello" , m.Text ().c_str ());
63
63
}
64
64
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
+
65
75
TEST (MessageChain_Test, GetAll) {
66
76
using namespace Cyan ;
67
77
MessageChain mc;
Original file line number Diff line number Diff line change @@ -99,6 +99,15 @@ namespace Cyan
99
99
return *this ;
100
100
}
101
101
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
+
102
111
template <class T >
103
112
void Remove (const T& m)
104
113
{
You can’t perform that action at this time.
0 commit comments