Changeset View
Changeset View
Standalone View
Standalone View
source/lobby/glooxwrapper/glooxwrapper.h
Show First 20 Lines • Show All 104 Lines • ▼ Show 20 Lines | namespace glooxwrapper | ||||
class ClientImpl; | class ClientImpl; | ||||
class MUCRoomHandlerWrapper; | class MUCRoomHandlerWrapper; | ||||
class SessionHandlerWrapper; | class SessionHandlerWrapper; | ||||
GLOOXWRAPPER_API void* glooxwrapper_alloc(size_t size); | GLOOXWRAPPER_API void* glooxwrapper_alloc(size_t size); | ||||
GLOOXWRAPPER_API void glooxwrapper_free(void* p); | GLOOXWRAPPER_API void glooxwrapper_free(void* p); | ||||
class string | using string = std::string; | ||||
{ | |||||
private: | |||||
size_t m_Size; | |||||
char* m_Data; | |||||
public: | |||||
string() | |||||
{ | |||||
m_Size = 0; | |||||
m_Data = (char*)glooxwrapper_alloc(1); | |||||
m_Data[0] = '\0'; | |||||
} | |||||
string(const string& str) | |||||
{ | |||||
m_Size = str.m_Size; | |||||
m_Data = (char*)glooxwrapper_alloc(m_Size + 1); | |||||
memcpy(m_Data, str.m_Data, m_Size + 1); | |||||
} | |||||
string(const std::string& str) : m_Data(NULL) | |||||
{ | |||||
m_Size = str.size(); | |||||
m_Data = (char*)glooxwrapper_alloc(m_Size + 1); | |||||
memcpy(m_Data, str.c_str(), m_Size + 1); | |||||
} | |||||
string(const char* str) | |||||
{ | |||||
m_Size = strlen(str); | |||||
m_Data = (char*)glooxwrapper_alloc(m_Size + 1); | |||||
memcpy(m_Data, str, m_Size + 1); | |||||
} | |||||
string& operator=(const string& str) | |||||
{ | |||||
if (this != &str) | |||||
{ | |||||
glooxwrapper_free(m_Data); | |||||
m_Size = str.m_Size; | |||||
m_Data = (char*)glooxwrapper_alloc(m_Size + 1); | |||||
memcpy(m_Data, str.m_Data, m_Size + 1); | |||||
} | |||||
return *this; | |||||
} | |||||
~string() | |||||
{ | |||||
glooxwrapper_free(m_Data); | |||||
} | |||||
/** | |||||
* Gloox strings are UTF encoded, so don't forget to decode it before passing it to the GUI! | |||||
*/ | |||||
std::string to_string() const | |||||
{ | |||||
return std::string(m_Data, m_Size); | |||||
} | |||||
const char* c_str() const | |||||
{ | |||||
return m_Data; | |||||
} | |||||
bool empty() const | |||||
{ | |||||
return m_Size == 0; | |||||
} | |||||
bool operator==(const char* str) const | |||||
{ | |||||
return strcmp(m_Data, str) == 0; | |||||
} | |||||
bool operator!=(const char* str) const | |||||
{ | |||||
return strcmp(m_Data, str) != 0; | |||||
} | |||||
bool operator==(const string& str) const | |||||
{ | |||||
return strcmp(m_Data, str.m_Data) == 0; | |||||
} | |||||
bool operator<(const string& str) const | |||||
{ | |||||
return strcmp(m_Data, str.m_Data) < 0; | |||||
} | |||||
}; | |||||
static inline std::ostream& operator<<(std::ostream& stream, const string& string) | static inline std::ostream& operator<<(std::ostream& stream, const string& string) | ||||
{ | { | ||||
return stream << string.c_str(); | return stream << string.c_str(); | ||||
} | } | ||||
template<typename T> | template<typename T> | ||||
class list | class list | ||||
▲ Show 20 Lines • Show All 279 Lines • ▼ Show 20 Lines | private: | ||||
gloox::JID* m_Wrapped; | gloox::JID* m_Wrapped; | ||||
bool m_Owned; | bool m_Owned; | ||||
void init(const char* data, size_t len); | void init(const char* data, size_t len); | ||||
public: | public: | ||||
const gloox::JID& getWrapped() const { return *m_Wrapped; } | const gloox::JID& getWrapped() const { return *m_Wrapped; } | ||||
JID(const gloox::JID& jid) : m_Wrapped(const_cast<gloox::JID*>(&jid)), m_Owned(false) { } | JID(const gloox::JID& jid) : m_Wrapped(const_cast<gloox::JID*>(&jid)), m_Owned(false) { } | ||||
JID(); | JID(); | ||||
JID(const string& jid); | JID(const std::string& jid); | ||||
JID(const std::string& jid) { init(jid.c_str(), jid.size()); } | |||||
~JID(); | ~JID(); | ||||
string username() const; | string username() const; | ||||
string resource() const; | string resource() const; | ||||
}; | }; | ||||
class GLOOXWRAPPER_API Message | class GLOOXWRAPPER_API Message | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 190 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator