Skip to content
Permalink
Browse files

Update nall, phoenix, and ruby to latest versions (except OpenGL driver)

  • Loading branch information...
Cydrak Cydrak
Cydrak authored and Cydrak committed Aug 3, 2013
1 parent c17a202 commit fd74475a25281b38b84ee9a331a54023eb573056
Showing 378 changed files with 7,324 additions and 6,407 deletions.
@@ -69,7 +69,9 @@ ifeq ($(platform),)
endif

ifneq ($(filter win cygwin,$(platform)),)
ruby += video.wgl audio.xaudio2 input.rawinput
ruby += video.wgl video.direct3d video.directdraw video.gdi
ruby += audio.xaudio2 audio.directsound
ruby += input.rawinput input.directinput

exe = .exe
CC := gcc -x c -std=gnu99
@@ -5,13 +5,15 @@
#undef max

namespace nall {
template<typename T, typename U> T min(const T &t, const U &u) {
return t < u ? t : u;
}

template<typename T, typename U> T max(const T &t, const U &u) {
return t > u ? t : u;
}
template<typename T, typename U> T min(const T& t, const U& u) {
return t < u ? t : u;
}

template<typename T, typename U> T max(const T& t, const U& u) {
return t > u ? t : u;
}

}

#endif
@@ -5,69 +5,94 @@
#include <nall/traits.hpp>

namespace nall {
struct any {
bool empty() const { return container; }
const std::type_info& type() const { return container ? container->type() : typeid(void); }

template<typename T> any& operator=(const T& value_) {
typedef typename type_if<
std::is_array<T>::value,
typename std::remove_extent<typename std::add_const<T>::type>::type*,
T
>::type auto_t;

if(type() == typeid(auto_t)) {
static_cast<holder<auto_t>*>(container)->value = (auto_t)value_;
} else {
if(container) delete container;
container = new holder<auto_t>((auto_t)value_);
}

return *this;
}

any() : container(nullptr) {}
~any() { if(container) delete container; }
template<typename T> any(const T& value_) : container(nullptr) { operator=(value_); }

private:
struct placeholder {
virtual const std::type_info& type() const = 0;
} *container;

template<typename T> struct holder : placeholder {
T value;
const std::type_info& type() const { return typeid(T); }
holder(const T& value_) : value(value_) {}
};

template<typename T> friend T any_cast(any&);
template<typename T> friend T any_cast(const any&);
template<typename T> friend T* any_cast(any*);
template<typename T> friend const T* any_cast(const any*);
};
struct any {
bool empty() const { return container; }
void reset() { if(container) { delete container; container = nullptr; } }

template<typename T> T any_cast(any &value) {
typedef typename std::remove_reference<T>::type nonref;
if(value.type() != typeid(nonref)) throw;
return static_cast<any::holder<nonref>*>(value.container)->value;
const std::type_info& type() const {
return container ? container->type() : typeid(void);
}

template<typename T> T any_cast(const any &value) {
typedef const typename std::remove_reference<T>::type nonref;
if(value.type() != typeid(nonref)) throw;
return static_cast<any::holder<nonref>*>(value.container)->value;
template<typename T> any& operator=(const T& value) {
typedef typename type_if<
std::is_array<T>::value,
typename std::remove_extent<typename std::add_const<T>::type>::type*,
T
>::type auto_t;

if(type() == typeid(auto_t)) {
static_cast<holder<auto_t>*>(container)->value = (auto_t)value;
} else {
if(container) delete container;
container = new holder<auto_t>((auto_t)value);
}

return *this;
}

template<typename T> T* any_cast(any *value) {
if(!value || value->type() != typeid(T)) return nullptr;
return &static_cast<any::holder<T>*>(value->container)->value;
any& operator=(const any& source) {
if(container) { delete container; container = nullptr; }
if(source.container) container = source.container->copy();
return *this;
}

template<typename T> const T* any_cast(const any *value) {
if(!value || value->type() != typeid(T)) return nullptr;
return &static_cast<any::holder<T>*>(value->container)->value;
any& operator=(any&& source) {
if(container) delete container;
container = source.container;
source.container = nullptr;
return *this;
}

any() = default;
any(const any& source) { operator=(source); }
any(any&& source) { operator=(std::move(source)); }
template<typename T> any(const T& value) { operator=(value); }
~any() { reset(); }

private:
struct placeholder {
virtual const std::type_info& type() const = 0;
virtual placeholder* copy() const = 0;
virtual ~placeholder() {}
};
placeholder* container = nullptr;

template<typename T> struct holder : placeholder {
T value;
const std::type_info& type() const { return typeid(T); }
placeholder* copy() const { return new holder(value); }
holder(const T& value) : value(value) {}
};

template<typename T> friend T any_cast(any&);
template<typename T> friend T any_cast(const any&);
template<typename T> friend T* any_cast(any*);
template<typename T> friend const T* any_cast(const any*);
};

template<typename T> T any_cast(any& value) {
typedef typename std::remove_reference<T>::type nonref;
if(value.type() != typeid(nonref)) throw;
return static_cast<any::holder<nonref>*>(value.container)->value;
}

template<typename T> T any_cast(const any& value) {
typedef const typename std::remove_reference<T>::type nonref;
if(value.type() != typeid(nonref)) throw;
return static_cast<any::holder<nonref>*>(value.container)->value;
}

template<typename T> T* any_cast(any* value) {
if(!value || value->type() != typeid(T)) return nullptr;
return &static_cast<any::holder<T>*>(value->container)->value;
}

template<typename T> const T* any_cast(const any* value) {
if(!value || value->type() != typeid(T)) return nullptr;
return &static_cast<any::holder<T>*>(value->container)->value;
}

}

#endif
@@ -5,34 +5,28 @@

namespace nall {

//note: this header is intended to form the base for user-defined literals;
//once they are supported by GCC. eg:
//unsigned operator "" b(const char *s) { return binary(s); }
//-> signed data = 1001b;
//(0b1001 is nicer, but is not part of the C++ standard)

constexpr inline uintmax_t binary_(const char *s, uintmax_t sum = 0) {
constexpr inline uintmax_t binary_(const char* s, uintmax_t sum = 0) {
return (
*s == '0' || *s == '1' ? binary_(s + 1, (sum << 1) | *s - '0') :
sum
);
}

constexpr inline uintmax_t octal_(const char *s, uintmax_t sum = 0) {
constexpr inline uintmax_t octal_(const char* s, uintmax_t sum = 0) {
return (
*s >= '0' && *s <= '7' ? octal_(s + 1, (sum << 3) | *s - '0') :
sum
);
}

constexpr inline uintmax_t decimal_(const char *s, uintmax_t sum = 0) {
constexpr inline uintmax_t decimal_(const char* s, uintmax_t sum = 0) {
return (
*s >= '0' && *s <= '9' ? decimal_(s + 1, (sum * 10) + *s - '0') :
sum
);
}

constexpr inline uintmax_t hex_(const char *s, uintmax_t sum = 0) {
constexpr inline uintmax_t hex_(const char* s, uintmax_t sum = 0) {
return (
*s >= 'A' && *s <= 'F' ? hex_(s + 1, (sum << 4) | *s - 'A' + 10) :
*s >= 'a' && *s <= 'f' ? hex_(s + 1, (sum << 4) | *s - 'a' + 10) :
@@ -43,7 +37,7 @@ constexpr inline uintmax_t hex_(const char *s, uintmax_t sum = 0) {

//

constexpr inline uintmax_t binary(const char *s) {
constexpr inline uintmax_t binary(const char* s) {
return (
*s == '0' && *(s + 1) == 'B' ? binary_(s + 2) :
*s == '0' && *(s + 1) == 'b' ? binary_(s + 2) :
@@ -52,27 +46,29 @@ constexpr inline uintmax_t binary(const char *s) {
);
}

constexpr inline uintmax_t octal(const char *s) {
constexpr inline uintmax_t octal(const char* s) {
return (
*s == '0' && *(s + 1) == 'O' ? octal_(s + 2) :
*s == '0' && *(s + 1) == 'o' ? octal_(s + 2) :
octal_(s)
);
}

constexpr inline intmax_t integer(const char *s) {
constexpr inline intmax_t integer(const char* s) {
return (
*s == '+' ? +decimal_(s + 1) :
*s == '-' ? -decimal_(s + 1) :
decimal_(s)
);
}

constexpr inline uintmax_t decimal(const char *s) {
constexpr inline uintmax_t decimal(const char* s) {
return (
decimal_(s)
);
}

constexpr inline uintmax_t hex(const char *s) {
constexpr inline uintmax_t hex(const char* s) {
return (
*s == '0' && *(s + 1) == 'X' ? hex_(s + 2) :
*s == '0' && *(s + 1) == 'x' ? hex_(s + 2) :
@@ -81,7 +77,7 @@ constexpr inline uintmax_t hex(const char *s) {
);
}

constexpr inline intmax_t numeral(const char *s) {
constexpr inline intmax_t numeral(const char* s) {
return (
*s == '0' && *(s + 1) == 'X' ? hex_(s + 2) :
*s == '0' && *(s + 1) == 'x' ? hex_(s + 2) :
@@ -94,7 +90,7 @@ constexpr inline intmax_t numeral(const char *s) {
);
}

inline double fp(const char *s) {
inline double real(const char* s) {
return atof(s);
}

0 comments on commit fd74475

Please sign in to comment.
You can’t perform that action at this time.