JKQTPlotter trunk/v5.0.0
an extensive Qt5+Qt6 Plotter framework (including a feature-richt plotter widget, a speed-optimized, but limited variant and a LaTeX equation renderer!), written fully in C/C++ and without external dependencies
Loading...
Searching...
No Matches
jkqtparraytools.h
1/*
2 Copyright (c) 2008-2024 Jan W. Krieger (<jan@jkrieger.de>)
3
4 last modification: $LastChangedDate$ (revision $Rev$)
5
6 This software is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License (LGPL) as published by
8 the Free Software Foundation, either version 2.1 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License (LGPL) for more details.
15
16 You should have received a copy of the GNU Lesser General Public License (LGPL)
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20
21#ifndef JKQTPARRAYTOOLS_H_INCLUDED
22#define JKQTPARRAYTOOLS_H_INCLUDED
23
24#include <stdint.h>
25#include <cmath>
26#include <stdlib.h>
27#include <string.h>
28#include <iostream>
29#include <stdio.h>
30#include <limits>
31#include <vector>
32#include <utility>
33#include <cfloat>
34#include <ostream>
35#include <iomanip>
36#include <sstream>
37#include "jkqtmath/jkqtmath_imexport.h"
38
39
40#ifdef _OPENMP
41# include <omp.h>
42#endif
43
44#ifndef __LINUX__
45# if defined(linux)
46# define __LINUX__
47# endif
48#endif
49
50#ifdef __LINUX__
51#include <malloc.h>
52#include <stdlib.h>
53#endif
54
55#ifndef JKQTP_ALIGNMENT_BYTES
56#define JKQTP_ALIGNMENT_BYTES 32
57#endif
58
59
60
61
62/*! \brief swap two elements \a l and \a r in an array \a a
63 \ingroup jkqtptools_math_array
64
65*/
66template <class T>
67inline void jkqtpArraySwap(T* a, long long l, long long r){
68 const T tmp=a[l];
69 a[l]=a[r];
70 a[r]=tmp;
71}
72
73/*! \brief swap two elements \a l and \a r in an array \a a
74 \ingroup jkqtptools_math_array
75
76*/
77template <class T>
78inline void jkqtpArraySwapV(std::vector<T>& a, long long l, long long r){
79 const T tmp=a[l];
80 a[l]=a[r];
81 a[r]=tmp;
82}
83
84
85
86/*! \brief duplicate an array of data
87 \ingroup jkqtptools_math_array
88
89 \note use free() to free the memory!!!
90*/
91template <class T>
92inline T* jkqtpArrayDuplicate(const T* dataIn, long long N) {
93// std::cout<<"statisticsDuplicateArray("<<dataIn<<", "<<N<<")\n";
94 if (N<=0 || !dataIn) return nullptr;
95 T* out=static_cast<T*>(malloc(N*sizeof(T)));
96 if (out) memcpy(out, dataIn, N*sizeof(T));
97 return out;
98}
99
100
101
102
103/*! \brief this class ensures that the given pointer is freed when the class is destroyed.
104 \ingroup jkqtptools_math_array
105
106*/
107template<typename T>
109 public:
110 inline explicit JKQTPArrayScopedPointer(T* pnt) {
111 pntr=pnt;
112 }
113 inline explicit JKQTPArrayScopedPointer() {
114 pntr=nullptr;
115 }
116 inline explicit JKQTPArrayScopedPointer(const JKQTPArrayScopedPointer& other) {
117 pntr=other.pntr;
118 }
119
120
122 if (pntr) free(pntr);
123 }
124
125
127 pntr=p;
128 return *this;
129 }
130
132 pntr=p.pntr;
133 return *this;
134 }
135
136 inline T& operator*() const { return *pntr; }
137 inline T* operator->() const { return pntr; }
138 inline T* data() const { return pntr; }
139 inline T& operator[](long long i) {
140 return pntr[i];
141 }
142 inline const T& operator[](long long i) const {
143 return pntr[i];
144 }
145
146
147
148 private:
150};
151
152#endif // JKQTPARRAYTOOLS_H_INCLUDED
153
154
this class ensures that the given pointer is freed when the class is destroyed.
Definition jkqtparraytools.h:108
JKQTPArrayScopedPointer(T *pnt)
Definition jkqtparraytools.h:110
JKQTPArrayScopedPointer< T > & operator=(T *p)
Definition jkqtparraytools.h:126
T * operator->() const
Definition jkqtparraytools.h:137
T & operator[](long long i)
Definition jkqtparraytools.h:139
T * pntr
Definition jkqtparraytools.h:149
JKQTPArrayScopedPointer< T > & operator=(const JKQTPArrayScopedPointer< T > &p)
Definition jkqtparraytools.h:131
~JKQTPArrayScopedPointer()
Definition jkqtparraytools.h:121
const T & operator[](long long i) const
Definition jkqtparraytools.h:142
T & operator*() const
Definition jkqtparraytools.h:136
T * data() const
Definition jkqtparraytools.h:138
JKQTPArrayScopedPointer()
Definition jkqtparraytools.h:113
JKQTPArrayScopedPointer(const JKQTPArrayScopedPointer &other)
Definition jkqtparraytools.h:116
void jkqtpArraySwap(T *a, long long l, long long r)
swap two elements l and r in an array a
Definition jkqtparraytools.h:67
T * jkqtpArrayDuplicate(const T *dataIn, long long N)
duplicate an array of data
Definition jkqtparraytools.h:92
void jkqtpArraySwapV(std::vector< T > &a, long long l, long long r)
swap two elements l and r in an array a
Definition jkqtparraytools.h:78