32 inline explicit BetwCompare(
const T& x) : x(x), ans(true) { }
33 #define RC_BETW_HELP(REL) \
35 inline BetwCompare operator REL (const T2& other) { \
45 inline operator
bool ()
const {
return ans; }
48 #define RC_BETW_HELP2(REL1, REL2) \
49 template<class T, class T2> \
50 inline BetwCompare<T> operator REL1 (const T2& other, BetwCompare<T> betw) { \
51 return betw REL2 other; \
69 BetwCompare<T>
Betw(const T& x) {
return BetwCompare<T>(x); }
74 template<
class... Args>
77 Tuple<Args...> compare;
79 OneOfCompare(Tuple<Args...>&& tup) : compare(tup) { }
80 template<
class T,
class... Args2>
81 friend bool operator==(
const T& item,
const OneOfCompare<Args2...>& list);
82 template<
class T,
class... Args2>
83 friend bool operator!=(
const T& item,
const OneOfCompare<Args2...>& list);
86 template<
class T,
class... Args>
87 bool operator== (
const T& item,
const OneOfCompare<Args...>& list) {
88 Data1D<T> arr = list.compare.template AsData<T>();
96 template<
class T,
class... Args>
97 bool operator!= (
const T& item,
const OneOfCompare<Args...>& list) {
98 return ! (item == list);
109 template<
class... Args>
110 OneOfCompare<Args...>
OneOf(Args... args) {
111 return OneOfCompare<Args...>(
Tuple<Args...>(args...));
122 inline LoopIndex(
size_t range) : index(0), range(range) { }
124 inline size_t Range()
const {
return range; }
126 inline void SetRange(
size_t new_range) { range = new_range; *
this = index; }
130 if (new_index > (
size_t(-1)/2)) {
131 index = range - ((0-new_index) % range);
134 index = new_index % range;
139 inline operator size_t ()
const {
return index; }
143 if (index>=range) { index=0; }
154 if (index==0) { index = range-1; }
167 if (offset > (
size_t(-1)/2)) {
168 size_t negoff = (0-offset)%range;
169 if (index < negoff) {
170 index = range - (negoff - index);
173 index = index - negoff;
177 index = (index + offset) % range;
184 return (*
this += 0-offset);
198 class DerefIncrement {
202 inline DerefIncrement(
const T& val) : val(val) { }
203 inline T
operator* ()
const {
return val; }
204 inline DerefIncrement& operator++ () { ++val;
return *
this; }
205 inline DerefIncrement& operator-- () { --val;
return *
this; }
206 inline bool operator== (
const DerefIncrement& other)
const {
207 return val == other.val;
209 inline bool operator!= (
const DerefIncrement& other)
const {
210 return val != other.val;
220 inline RangeHelper(
const T& start,
const T& past_the_end) :
221 start(start), past_the_end(past_the_end) { }
222 inline DerefIncrement<T> begin()
const {
return start; }
223 inline DerefIncrement<T> cbegin()
const {
return start; }
224 inline DerefIncrement<T> end()
const {
return past_the_end; }
225 inline DerefIncrement<T> cend()
const {
return past_the_end; }
226 inline DerefIncrement<T> rbegin()
const {
return past_the_end-1; }
227 inline DerefIncrement<T> crbegin()
const {
return past_the_end-1; }
228 inline DerefIncrement<T> rend()
const {
return start-1; }
229 inline DerefIncrement<T> crend()
const {
return start-1; }
243 inline RangeHelper<T>
Range(
const T& start,
const T& past_the_end) {
244 return RangeHelper<T>(start, past_the_end);
254 inline auto IndexOf(
const T2& cont) -> RangeHelper<decltype(cont.size())> {
255 return RangeHelper<decltype(cont.size())>(0, cont.size());
263 template<
class Hold,
class Prov
ide>
274 : held(std::move(held)), give(std::move(give)) { }
278 void Set(Provide new_give) { give = std::move(new_give); }
280 HoldRelated(Hold held, Provide give) : held(held), give(give) { }
282 void Set(Provide new_give) { give = new_give; }
285 operator Provide() {
return give; }
287 operator const Provide()
const {
return give; }
289 const Provide
Get()
const {
return give; }
291 Provide
Get() {
return give; }
293 const Hold&
Held()
const {
return held; }
304 template<
class ClassTracking,
bool stack_trace=false>
308 #define RC_DEBUG_TRACK_OUT(label) \
309 std::string name = typeid(ClassTracking).name(); \
310 std::stringstream sstr; \
311 sstr << "[" << this << "] -> "; \
314 ErrorMsg e(sstr.str().c_str()); \
315 sstr.str(std::string()); \
319 RC_DEBOUT_STREAM << sstr.str();
322 RC_DEBUG_TRACK_OUT(name +
"() [Construct]");
325 RC_DEBUG_TRACK_OUT(
"~" + name +
"() [Destruct]");
328 RC_DEBUG_TRACK_OUT(name +
"(const "+name+
"&) [Copy Construct]");
331 RC_DEBUG_TRACK_OUT(name+
"& operator=(const "+name+
"&) [Copy Assignment]");
336 RC_DEBUG_TRACK_OUT(name +
"(" + name +
"&&) [Move Construct]");
339 RC_DEBUG_TRACK_OUT(name +
"& operator=("+name+
"&&) [Move Assignment]");
363 library = dlopen(libname, RTLD_LAZY | RTLD_GLOBAL);
365 library = LoadLibrary(libname);
376 class DynamicFunction {
380 DynamicFunction(DynamicLibrary& dyn_lib,
const char (&funcname)[N]) {
382 func = T(dlsym(dyn_lib.library, funcname));
384 func = T(GetProcAddress(dyn_lib.library, funcname));
391 template<
class... Args>
392 auto operator()(Args... args) -> decltype((*func)(args...)) {
393 return (*func)(args...);
411 #define RC_DYNAMIC_LOAD_FUNC(FuncName,DynLib) \
412 static RC::DynamicFunction<decltype(FuncName)> FuncName{DynLib, #FuncName};
418 template<
class T,
class T2>
420 bool out_of_bounds =
false;
422 if (IsIntegerType<T>()) {
423 if (intmax_t(x) < intmax_t(LOW_VAL<T>())) {
424 out_of_bounds =
true;
426 else if (x > 0 && uintmax_t(x) > uintmax_t(MAX_VAL<T>())) {
427 out_of_bounds =
true;
432 out_of_bounds =
true;
435 out_of_bounds =
true;
446 template<
class T,
class T2>
448 if (IsIntegerType<T>()) {
449 if (intmax_t(x) < intmax_t(LOW_VAL<T>())) {
452 if (x > 0 && uintmax_t(x) > uintmax_t(MAX_VAL<T>())) {
Provides informative exception handling.
#define Throw_RC_Type(Type, err)
Use this to throw an RC:ErrorMsg subtype exception.
Definition: Errors.h:282
T & operator*()
Dereferences the pointer, or throws an exception if null.
Definition: PtrCommon.h:38
The version information and configuration settings for RC Lib.
Provides a Tuple class which can apply its contents as function parameters.
Provides typedefs and routines for working with primitives.
f128 fBIGGEST
The biggest float type available.
Definition: Types.h:49
Inherit this class to add construction, destruction, and assignment output tracking.
Definition: RCBits.h:305
Opens a dynamic library filename and stores a handle to it. Use as second parameter for RC_DYNAMIC_LO...
Definition: RCBits.h:351
void * library
Direct access to the loaded library.
Definition: RCBits.h:355
DynamicLibrary(const char(&libname)[N])
Loads the library of the given name.
Definition: RCBits.h:361
A class with static methods for file and directory info and manipulation.
Definition: File.h:1214
A size_t like integer class which automatically stays within its range.
Definition: RCBits.h:119
LoopIndex & operator++()
Increment by one, looping within range.
Definition: RCBits.h:141
size_t Range() const
Returns the set range.
Definition: RCBits.h:124
LoopIndex & operator=(size_t new_index)
Assigns a new index value, forcing it in the range. Signed indices are handled properly.
Definition: RCBits.h:129
LoopIndex(size_t range)
Defines the range of of the object. The index is always less than this.
Definition: RCBits.h:122
LoopIndex & operator-=(size_t offset)
Decrement by offset, looping within range, and handling negative offsets correctly.
Definition: RCBits.h:183
LoopIndex & operator--()
Decrement by one, looping within range.
Definition: RCBits.h:153
LoopIndex & operator+=(size_t offset)
Increment by offset, looping within range, and handling negative offsets correctly.
Definition: RCBits.h:166
void SetRange(size_t new_range)
Sets a new range.
Definition: RCBits.h:126
An efficient Tuple class with Set, Get, and an Apply function to pass the tuple contents on to any fu...
Definition: Tuple.h:62
T CheckedCast(const T2 &x)
For integer and floating point types, Throws RC::ErrorMsgBounds if the value of x does not fit into T...
Definition: RCBits.h:419
BetwCompare< T > Betw(const T &x)
Returns a comparator that can be used for range comparisons.
Definition: RCBits.h:69
bool operator!=(const RStr &lhs, const RStr &rhs)
True if lhs does not equal rhs.
Definition: RStr.h:2276
OneOfCompare< Args... > OneOf(Args... args)
Returns a comparator that can be used to check if something is in a list.
Definition: RCBits.h:110
auto IndexOf(const T2 &cont) -> RangeHelper< decltype(cont.size())>
Provides an iterator which dereferences to the indices of cont from [0,cont.size()).
Definition: RCBits.h:254
T CappedCast(const T2 &x)
For integer and floating point types, caps the cast value of x to be within bounds of type T....
Definition: RCBits.h:447
bool operator==(const RStr &lhs, const RStr &rhs)
True if lhs equals rhs.
Definition: RStr.h:2271
RangeHelper< T > Range(const T &start, const T &past_the_end)
Provides an iterator which dereferences to the iterated values [start,past_the_end).
Definition: RCBits.h:243