Fix C++11 usage in native with platform-specific hacks.

This commit is contained in:
Sacha committed 2013-06-02 13:06:40 +10:00
1 parent 4267d9903c
commit 58c40dabb1
6 files changed
+49 -56

No files matched your search

+36 -7
View File
@@ -1,24 +1,53 @@
// This file simply includes <functional> and applies any necessary compatibility fixes for
// strange platforms like iOS.
// Use p as the namespace for placeholders.
// Use placeholder as the namespace for placeholders.
#pragma once
#include <functional>
#ifdef __SYMBIAN32__
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <boost/weak_ptr.hpp>
using namespace boost;
#else
#include <memory>
using namespace std;
#endif
#include <vector>
#if defined(IOS) || defined(MACGNUSTD)
#if defined(__SYMBIAN32__) || defined(IOS) || defined(MACGNUSTD)
#ifndef __SYMBIAN32__
#include <tr1/functional>
#include <tr1/memory>
#endif
namespace std {
using tr1::bind;
#ifndef __SYMBIAN32__
using tr1::bind;
using tr1::function;
using tr1::shared_ptr;
#endif
template <typename T>
inline shared_ptr<T> make_shared()
{
return shared_ptr<T>(new T());
}
template <typename T, typename Arg1>
inline shared_ptr<T> make_shared(Arg1& arg1)
{
return shared_ptr<T>(new T(arg1));
}
}
#endif
#ifdef __SYMBIAN32__
#define p
#define placeholder
#elif defined(IOS)
#include <tr1/functional>
namespace p = std::tr1::placeholders;
namespace placeholder = std::tr1::placeholders;
#else
namespace p = std::placeholders;
namespace placeholder = std::placeholders;
#endif
+3 -4
View File
@@ -19,7 +19,6 @@
#include "base/stringutil.h"
#include "net/resolve.h"
#include "net/url.h"
#include "base/functional.h"
// #include "strings/strutil.h"
@@ -175,7 +174,7 @@ int Client::POST(const char *resource, const std::string &data, Buffer *output)
Download::Download(const std::string &url, const std::string &outfile)
: url_(url), outfile_(outfile), progress_(0.0f), failed_(false) {
std::thread th(std::bind(&Download::Do, this));
std::thread th(bind(&Download::Do, this));
th.detach();
}
@@ -211,8 +210,8 @@ void Download::Do() {
net::Shutdown();
}
std::shared_ptr<Download> Downloader::StartDownload(const std::string &url, const std::string &outfile) {
std::shared_ptr<Download> dl(new Download(url, outfile));
shared_ptr<Download> Downloader::StartDownload(const std::string &url, const std::string &outfile) {
shared_ptr<Download> dl(new Download(url, outfile));
downloads_.push_back(dl);
return dl;
}
+3 -2
View File
@@ -5,6 +5,7 @@
#include "base/basictypes.h"
#include "base/buffer.h"
#include "thread/thread.h"
#include "base/functional.h"
#ifdef _WIN32
#include <winsock2.h>
@@ -98,13 +99,13 @@ private:
class Downloader {
public:
std::shared_ptr<Download> StartDownload(const std::string &url, const std::string &outfile);
shared_ptr<Download> StartDownload(const std::string &url, const std::string &outfile);
// Drops finished downloads from the list.
void Update();
private:
std::vector<std::shared_ptr<Download>> downloads_;
std::vector<shared_ptr<Download>> downloads_;
};
+2 -38
View File
@@ -2,44 +2,7 @@
#include "thread.h"
#include "base/mutex.h"
#include <functional>
#ifdef __SYMBIAN32__
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <boost/weak_ptr.hpp>
using namespace boost;
#else
#include <memory>
using namespace std;
#endif
#include <vector>
#if defined(__SYMBIAN32__) || defined(IOS) || defined(MACGNUSTD)
#ifndef __SYMBIAN32__
#include <tr1/functional>
#include <tr1/memory>
#endif
namespace std {
#ifndef __SYMBIAN32__
using tr1::bind;
using tr1::function;
using tr1::shared_ptr;
#endif
template <typename T>
inline shared_ptr<T> make_shared()
{
return shared_ptr<T>(new T());
}
template <typename T, typename Arg1>
inline shared_ptr<T> make_shared(Arg1& arg1)
{
return shared_ptr<T>(new T(arg1));
}
}
#endif
#include "base/functional.h"
// This is the simplest possible worker implementation I can think of
// but entirely sufficient for the given purpose.
@@ -90,3 +53,4 @@ private:
ThreadPool(const ThreadPool& other); // prevent copies
void operator =(const WorkerThread &other);
};
+1 -1
View File
@@ -49,7 +49,7 @@ void MeasureBySpec(Size sz, float contentWidth, MeasureSpec spec, float *measure
}
}
void Event::Add(std::function<EventReturn(EventParams&)> func) {
void Event::Add(function<EventReturn(EventParams&)> func) {
HandlerRegistration reg;
reg.func = func;
handlers_.push_back(reg);
+4 -4
View File
@@ -157,14 +157,14 @@ struct EventParams {
};
struct HandlerRegistration {
std::function<EventReturn(EventParams&)> func;
function<EventReturn(EventParams&)> func;
};
class Event {
public:
Event() : triggered_(false) {}
void Add(std::function<EventReturn(EventParams&)> func);
void Add(function<EventReturn(EventParams&)> func);
// Call this from input thread or whatever, it doesn't matter
void Trigger(EventParams &e);
@@ -410,7 +410,7 @@ class CheckBox : public ClickableItem {
public:
CheckBox(bool *toggle, const std::string &text, const std::string &smallText = "", LayoutParams *layoutParams = 0)
: ClickableItem(layoutParams), text_(text), smallText_(smallText) {
OnClick.Add(std::bind(&CheckBox::OnClicked, this, p::_1));
OnClick.Add(bind(&CheckBox::OnClicked, this, placeholder::_1));
}
virtual void Draw(UIContext &dc);
@@ -501,4 +501,4 @@ private:
void MeasureBySpec(Size sz, float contentWidth, MeasureSpec spec, float *measured);
} // namespace
} // namespace