From 02a6e34ed27def5c85392b22bb4def518334edb5 Mon Sep 17 00:00:00 2001 From: "pieter.vantorre" Date: Wed, 27 Apr 2016 11:42:14 +0200 Subject: [PATCH] don't use namespace std in publicly exposed code. Doing so is bad practice. In our case, we override enable_if in our engine, and the compiler got confused. --- src/sio_message.h | 188 +++++++++++++++++++++++----------------------- 1 file changed, 93 insertions(+), 95 deletions(-) diff --git a/src/sio_message.h b/src/sio_message.h index e46cdf21..6ad0d9b9 100755 --- a/src/sio_message.h +++ b/src/sio_message.h @@ -14,8 +14,6 @@ #include namespace sio { - using namespace std; - class message { public: @@ -32,84 +30,84 @@ namespace sio }; virtual ~message(){}; - + class list; flag get_flag() const { return _flag; } - - typedef shared_ptr ptr; + + typedef std::shared_ptr ptr; virtual bool get_bool() const { assert(false); return false; } - + virtual int64_t get_int() const { assert(false); return 0; } - + virtual double get_double() const { assert(false); return 0; } - - virtual string const& get_string() const + + virtual std::string const& get_string() const { assert(false); - static string s_empty_string; + static std::string s_empty_string; s_empty_string.clear(); return s_empty_string; } - - virtual shared_ptr const& get_binary() const + + virtual std::shared_ptr const& get_binary() const { assert(false); - static shared_ptr s_empty_binary; + static std::shared_ptr s_empty_binary; s_empty_binary = nullptr; return s_empty_binary; } - - virtual const vector& get_vector() const + + virtual const std::vector& get_vector() const { assert(false); - static vector s_empty_vector; + static std::vector s_empty_vector; s_empty_vector.clear(); return s_empty_vector; } - virtual vector& get_vector() + virtual std::vector& get_vector() { assert(false); - static vector s_empty_vector; + static std::vector s_empty_vector; s_empty_vector.clear(); return s_empty_vector; } - - virtual const map& get_map() const + + virtual const std::map& get_map() const { assert(false); - static map s_empty_map; + static std::map s_empty_map; s_empty_map.clear(); return s_empty_map; } - - virtual map& get_map() + + virtual std::map& get_map() { assert(false); - static map s_empty_map; + static std::map s_empty_map; s_empty_map.clear(); return s_empty_map; } private: flag _flag; - + protected: message(flag f):_flag(f){} }; @@ -138,19 +136,19 @@ namespace sio :message(flag_boolean),_v(v) { } - + public: static message::ptr create(bool v) { return ptr(new bool_message(v)); } - + bool get_bool() const { return _v; } }; - + class int_message : public message { int64_t _v; @@ -159,24 +157,24 @@ namespace sio :message(flag_integer),_v(v) { } - + public: static message::ptr create(int64_t v) { return ptr(new int_message(v)); } - + int64_t get_int() const { return _v; } - + double get_double() const//add double accessor for integer. { return static_cast(_v); } }; - + class double_message : public message { double _v; @@ -184,74 +182,74 @@ namespace sio :message(flag_double),_v(v) { } - + public: static message::ptr create(double v) { return ptr(new double_message(v)); } - + double get_double() const { return _v; } }; - + class string_message : public message { - string _v; - string_message(string const& v) + std::string _v; + string_message(std::string const& v) :message(flag_string),_v(v) { } - string_message(string&& v) + string_message(std::string&& v) :message(flag_string),_v(move(v)) { } public: - static message::ptr create(string const& v) + static message::ptr create(std::string const& v) { return ptr(new string_message(v)); } - static message::ptr create(string&& v) + static message::ptr create(std::string&& v) { return ptr(new string_message(move(v))); } - - string const& get_string() const + + std::string const& get_string() const { return _v; } }; - + class binary_message : public message { - shared_ptr _v; - binary_message(shared_ptr const& v) + std::shared_ptr _v; + binary_message(std::shared_ptr const& v) :message(flag_binary),_v(v) { } public: - static message::ptr create(shared_ptr const& v) + static message::ptr create(std::shared_ptr const& v) { return ptr(new binary_message(v)); } - - shared_ptr const& get_binary() const + + std::shared_ptr const& get_binary() const { return _v; } }; - + class array_message : public message { - vector _v; + std::vector _v; array_message():message(flag_array) { } - + public: static message::ptr create() { @@ -264,23 +262,23 @@ namespace sio _v.push_back(message); } - void push(const string& text) + void push(const std::string& text) { _v.push_back(string_message::create(text)); } - void push(string&& text) + void push(std::string&& text) { _v.push_back(string_message::create(move(text))); } - void push(shared_ptr const& binary) + void push(std::shared_ptr const& binary) { if(binary) _v.push_back(binary_message::create(binary)); } - void push(shared_ptr const& binary) + void push(std::shared_ptr const& binary) { if(binary) _v.push_back(binary_message::create(binary)); @@ -291,23 +289,23 @@ namespace sio _v.insert(_v.begin()+pos, message); } - void insert(size_t pos,const string& text) + void insert(size_t pos,const std::string& text) { _v.insert(_v.begin()+pos, string_message::create(text)); } - void insert(size_t pos,string&& text) + void insert(size_t pos,std::string&& text) { _v.insert(_v.begin()+pos, string_message::create(move(text))); } - void insert(size_t pos,shared_ptr const& binary) + void insert(size_t pos,std::shared_ptr const& binary) { if(binary) _v.insert(_v.begin()+pos, binary_message::create(binary)); } - void insert(size_t pos,shared_ptr const& binary) + void insert(size_t pos,std::shared_ptr const& binary) { if(binary) _v.insert(_v.begin()+pos, binary_message::create(binary)); @@ -328,20 +326,20 @@ namespace sio return _v[i]; } - vector& get_vector() + std::vector& get_vector() { return _v; } - - const vector& get_vector() const + + const std::vector& get_vector() const { return _v; } }; - + class object_message : public message { - map _v; + std::map _v; object_message() : message(flag_object) { } @@ -351,63 +349,63 @@ namespace sio return ptr(new object_message()); } - void insert(const string & key,message::ptr const& message) + void insert(const std::string & key,message::ptr const& message) { _v[key] = message; } - void insert(const string & key,const string& text) + void insert(const std::string & key,const std::string& text) { _v[key] = string_message::create(text); } - void insert(const string & key,string&& text) + void insert(const std::string & key,std::string&& text) { _v[key] = string_message::create(move(text)); } - void insert(const string & key,shared_ptr const& binary) + void insert(const std::string & key,std::shared_ptr const& binary) { if(binary) _v[key] = binary_message::create(binary); } - void insert(const string & key,shared_ptr const& binary) + void insert(const std::string & key,std::shared_ptr const& binary) { if(binary) _v[key] = binary_message::create(binary); } - bool has(const string & key) + bool has(const std::string & key) { return _v.find(key) != _v.end(); } - const message::ptr& at(const string & key) const + const message::ptr& at(const std::string & key) const { - static shared_ptr not_found; + static std::shared_ptr not_found; - map::const_iterator it = _v.find(key); - if (it != _v.end()) return it->second; + std::map::const_iterator it = _v.find(key); + if (it != _v.cend()) return it->second; return not_found; } - const message::ptr& operator[] (const string & key) const + const message::ptr& operator[] (const std::string & key) const { return at(key); } - bool has(const string & key) const + bool has(const std::string & key) const { return _v.find(key) != _v.end(); } - map& get_map() + std::map& get_map() { return _v; } - - const map& get_map() const + + const std::map& get_map() const { return _v; } @@ -420,7 +418,7 @@ namespace sio { } - list(nullptr_t) + list(std::nullptr_t) { } @@ -438,7 +436,7 @@ namespace sio template list(T&& content, - typename enable_if,typename remove_reference::type>::value>::type* = 0): + typename std::enable_if,typename std::remove_reference::type>::value>::type* = 0): m_vector(std::forward(content)) { } @@ -456,23 +454,23 @@ namespace sio } - list(const string& text) + list(const std::string& text) { m_vector.push_back(string_message::create(text)); } - list(string&& text) + list(std::string&& text) { m_vector.push_back(string_message::create(move(text))); } - list(shared_ptr const& binary) + list(std::shared_ptr const& binary) { if(binary) m_vector.push_back(binary_message::create(binary)); } - list(shared_ptr const& binary) + list(std::shared_ptr const& binary) { if(binary) m_vector.push_back(binary_message::create(binary)); @@ -484,23 +482,23 @@ namespace sio m_vector.push_back(message); } - void push(const string& text) + void push(const std::string& text) { m_vector.push_back(string_message::create(text)); } - void push(string&& text) + void push(std::string&& text) { m_vector.push_back(string_message::create(move(text))); } - void push(shared_ptr const& binary) + void push(std::shared_ptr const& binary) { if(binary) m_vector.push_back(binary_message::create(binary)); } - void push(shared_ptr const& binary) + void push(std::shared_ptr const& binary) { if(binary) m_vector.push_back(binary_message::create(binary)); @@ -511,23 +509,23 @@ namespace sio m_vector.insert(m_vector.begin()+pos, message); } - void insert(size_t pos,const string& text) + void insert(size_t pos,const std::string& text) { m_vector.insert(m_vector.begin()+pos, string_message::create(text)); } - void insert(size_t pos,string&& text) + void insert(size_t pos,std::string&& text) { m_vector.insert(m_vector.begin()+pos, string_message::create(move(text))); } - void insert(size_t pos,shared_ptr const& binary) + void insert(size_t pos,std::shared_ptr const& binary) { if(binary) m_vector.insert(m_vector.begin()+pos, binary_message::create(binary)); } - void insert(size_t pos,shared_ptr const& binary) + void insert(size_t pos,std::shared_ptr const& binary) { if(binary) m_vector.insert(m_vector.begin()+pos, binary_message::create(binary)); @@ -548,7 +546,7 @@ namespace sio return m_vector[i]; } - message::ptr to_array_message(string const& event_name) const + message::ptr to_array_message(std::string const& event_name) const { message::ptr arr = array_message::create(); arr->get_vector().push_back(string_message::create(event_name)); @@ -564,7 +562,7 @@ namespace sio } private: - vector m_vector; + std::vector m_vector; }; }