2 * LibSylph Class Library
3 * Copyright (C) 2009 Frank "SeySayux" Erens <seysayux@gmail.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the LibSylph Pulbic License as published
7 * by the LibSylph Developers; either version 1.0 of the License, or
8 * (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the LibSylph
13 * Public License for more details.
15 * You should have received a copy of the LibSylph Public License
16 * along with this Library, if not, contact the LibSylph Developers.
18 * Created on 9 december 2008, 15:34
24 #include "Object.h" // macros
25 #include "Exception.h"
34 inline void carraycopy(const T src
[], std::size_t srcPos
, T dest
[],
35 std::size_t destPos
, std::size_t length
) throw (Exception
) {
36 for (int i
= 0; i
< length
; i
++) {
37 dest
[destPos
+ i
] = src
[srcPos
+ i
];
42 inline void arraycopy(const Array
<T
> & src
, std::size_t srcPos
, Array
<T
> & dest
,
43 std::size_t destPos
, std::size_t length
) throw (Exception
) {
45 std::size_t srcSize
= src
.length
;
46 std::size_t destSize
= dest
.length
;
47 if (srcPos
+ length
> srcSize
) sthrow(ArrayException
, "Source array too short");
48 if (destPos
+ length
> destSize
) sthrow(ArrayException
, "Dest array too short");
50 for (int i
= 0; i
< length
; i
++) {
51 dest
[destPos
+ i
] = src
[srcPos
+ i
];
55 template <typename T
, std::size_t N
>
56 inline std::size_t carraysize(T(&)[N
]) {
60 template<class T
, class U
= T
>
62 return t
> 0 ? t
: -t
;
66 inline unsigned int abs
<int, unsigned int>(int t
) {
67 return t
> 0 ? t
: -t
;
71 inline unsigned long abs
<long, unsigned long>(long t
) {
72 return t
> 0 ? t
: -t
;
76 inline unsigned short abs
<short, unsigned short>(short t
) {
77 return t
> 0 ? t
: -t
;
81 inline signed char sign(T t
) {
82 return t
> 0? : t
== 0? 0 : -1;
86 inline signed char sign
<double>(double t
) {
87 return copysign(1.0,t
);
92 inline signed char sign
<float>(float t
) {
93 return copysignf(1.0f
, t
);