Changeset 11 in chevmsgr
Legend:
- Unmodified
- Added
- Removed
-
trunk/msg.cpp
r8 r11 7 7 namespace Protocol 8 8 { 9 // parser 9 Message::Message() 10 { 11 mObject[ProtocolType::TYPE] = ProtocolType::NONE; 12 } 13 10 14 void Message::parse(const std::string & message) 11 15 { … … 15 19 std::string Message::type() const 16 20 { 17 return get<std::string>( "type");21 return get<std::string>(ProtocolType::TYPE); 18 22 } 19 23 … … 29 33 SFriend fr; 30 34 31 fr.id = (*iter)[ProtocolType::ID 35 fr.id = (*iter)[ProtocolType::ID]; 32 36 fr.name = (*iter)[ProtocolType::NAME]; 33 37 … … 146 150 json::Object fr; 147 151 148 fr[ProtocolType::ID 152 fr[ProtocolType::ID] = iter->id; 149 153 fr[ProtocolType::NAME] = iter->name; 150 154 -
trunk/msg.hpp
r8 r11 23 23 #define DECLARE_KEY(_t) static const std::string _t = #_t 24 24 25 DECLARE_KEY(NONE); 25 26 DECLARE_KEY(ID); 26 27 DECLARE_KEY(TYPE); … … 41 42 DECLARE_KEY(GET_FRIEND_LIST); 42 43 DECLARE_KEY(FRIEND_LIST); 44 DECLARE_KEY(ID_LIST); 43 45 DECLARE_KEY(RESULT); 44 46 } … … 52 54 53 55 public: 54 void parse(const std::string & message); 56 Message(); 57 58 inline void parse(const std::string & message); 55 59 56 60 template<typename T> … … 60 64 } 61 65 66 template<typename T> 67 inline std::vector<T> getList(const std::string & key) const 68 { 69 std::vector<T> ret; 70 json::Array ar = mObject[key]; 71 72 for (size_t iter = 0; iter < ar.size(); iter++) 73 ret.push_back(ar[iter]); 74 75 return ret; 76 } 77 62 78 inline std::vector<SFriend> getFriendList() const; 63 79 64 std::string type() const;80 inline std::string type() const; 65 81 }; 66 82 … … 77 93 78 94 public: 79 void setUserID(const std::string & id);95 inline void setUserID(const std::string & id); 80 96 81 const std::string & getUserID();97 inline const std::string & getUserID(); 82 98 83 void makeTemplate(json::Object & obj, const std::string & type) const;99 inline void makeTemplate(json::Object & obj, const std::string & type) const; 84 100 85 std::string sms(const std::string & phone) const;101 inline std::string sms(const std::string & phone) const; 86 102 87 std::string join(const std::string & id, const std::string & pw, const std::string & sms);103 inline std::string join(const std::string & id, const std::string & pw, const std::string & sms); 88 104 89 std::string login(const std::string & pw) const;105 inline std::string login(const std::string & pw) const; 90 106 91 std::string addFriend(const std::string & id) const;107 inline std::string addFriend(const std::string & id) const; 92 108 93 std::string openSession(const std::string & to) const;109 inline std::string openSession(const std::string & to) const; 94 110 95 std::string chat(const std::string & sessid, const std::string & message, const int sensitive) const;111 inline std::string chat(const std::string & sessid, const std::string & message, const int sensitive) const; 96 112 97 std::string getFriendList() const;113 inline std::string getFriendList() const; 98 114 }; 99 115 … … 101 117 { 102 118 public: 103 void makeTemplate(json::Object & obj, const std::string & type) const;119 inline void makeTemplate(json::Object & obj, const std::string & type) const; 104 120 105 std::string result(const std::string & requestType, const bool status) const;121 inline std::string result(const std::string & requestType, const bool status) const; 106 122 107 std::string friendList(const std::vector<SFriend> & friendList) const;123 inline std::string friendList(const std::vector<SFriend> & friendList) const; 108 124 109 std::string openSession(const std::vector<std::string> & idList) const;125 inline std::string openSession(const std::vector<std::string> & idList) const; 110 126 }; 111 127 }; … … 134 150 << message << std::endl; 135 151 } 152 153 static std::string joinStrings(const std::vector<std::string> & strings) 154 { 155 std::string concat = strings[0]; 156 157 for (size_t iter = 1; iter < strings.size(); iter++) 158 concat += DELIMITER + strings[iter]; 159 160 return concat; 161 }
Note:
See TracChangeset
for help on using the changeset viewer.