ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
StaticVector.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <assert.h>
11 #include <zlib.h> // do not include this in header due to undefined symbols unzReadCurrentFile
12 
13 #include <algorithm>
14 #include <cstdlib>
15 #include <iostream>
16 #include <sstream>
17 #include <stdexcept>
18 #include <vector>
19 
20 #include "CVLog.h"
21 #include "FileSystem.h"
22 
23 namespace cloudViewer {
24 
25 template <class T>
27  std::vector<T> _data;
28 
29  typedef typename std::vector<T>::iterator Iterator;
30  typedef typename std::vector<T>::const_iterator ConstIterator;
31  typedef typename std::vector<T>::reference Reference;
32  typedef typename std::vector<T>::const_reference ConstReference;
33 
34 public:
36 
37  StaticVector(int n) : _data(n) {}
38 
39  StaticVector(int n, const T& value) : _data(n, value) {}
40 
41  const T& operator[](int index) const { return _data[index]; }
42 
43  T& operator[](int index) { return _data[index]; }
44 
45  void clear() { _data.clear(); }
46 
47  Iterator begin() { return _data.begin(); }
48  Iterator end() { return _data.end(); }
49 
50  ConstIterator begin() const { return _data.begin(); }
51  ConstIterator end() const { return _data.end(); }
52 
53  Reference front() { return _data.front(); }
54  ConstReference front() const { return _data.front(); }
55 
56  Reference back() { return _data.back(); }
57  ConstReference back() const { return _data.back(); }
58 
59  const std::vector<T>& getData() const { return _data; }
60  std::vector<T>& getDataWritable() { return _data; }
61  int size() const { return _data.size(); }
62  bool empty() const { return _data.empty(); }
63  size_t capacity() const { return _data.capacity(); }
64  void reserve(int n) { _data.reserve(n); }
65  void resize(int n) { _data.resize(n); }
66  void resize(int n, T value) { _data.resize(n, value); }
67  void resize_with(int n, const T& val) { _data.resize(n, val); }
68  void swap(StaticVector& other) { _data.swap(other._data); }
69  void assign(int n, T value) { _data.assign(n, value); }
70 
71  void shrink_to_fit() { _data.shrink_to_fit(); }
72 
73  void reserveAddIfNeeded(int nplanned, int ntoallocated) {
74  if (size() + nplanned > capacity()) {
75  reserveAdd(nplanned + ntoallocated);
76  }
77  }
78 
79  void reserveAdd(int ntoallocated) {
80  _data.reserve(capacity() + ntoallocated);
81  }
82 
83  void push_back(const T& val) { _data.push_back(val); }
84 
85  void push_front(const T& val) { _data.insert(_data.begin(), val); }
86 
88  _data.insert(_data.end(), arr->getData().begin(), arr->getData().end());
89  }
90 
92  _data.insert(_data.end(), arr.getData().begin(), arr.getData().end());
93  }
94 
95  void remove(int i) { _data.erase(_data.begin() + i); }
96 
97  int push_back_distinct(const T& val) {
98  int id = indexOf(val);
99  if (id == -1) _data.push_back(val);
100  return id;
101  }
102 
103  T pop() {
104  T val = _data.back();
105  _data.pop_back();
106  return val;
107  }
108 
109  int indexOf(const T& value) const {
110  const auto it = std::find(_data.begin(), _data.end(), value);
111  return it != _data.end() ? std::distance(_data.begin(), it) : -1;
112  }
113 
114  int indexOfSorted(const T& value) const { return indexOf(value); }
115 
116  int indexOfNearestSorted(const T& value) const {
117  // Retrieve the first element >= value in _data
118  auto it = std::lower_bound(_data.begin(), _data.end(), value);
119  if (it == _data.end()) return -1;
120  // If we're between two values...
121  if (it != _data.begin()) {
122  // ...select the index of the closest value between it (>= value)
123  // and prevIt (< value)
124  auto prevIt = std::prev(it);
125  it = (value - *prevIt) < (*it - value) ? prevIt : it;
126  }
127  return std::distance(_data.begin(), it);
128  }
129 
130  int minValId() const {
131  if (_data.empty()) return -1;
132  return std::distance(_data.begin(),
133  std::min_element(_data.begin(), _data.end()));
134  }
135 
136  int maxValId() const {
137  if (_data.empty()) return -1;
138  return std::distance(_data.begin(),
139  std::max_element(_data.begin(), _data.end()));
140  }
141 };
142 
143 // TODO: to remove
144 // Avoid the problematic case of std::vector<bool>::operator[]
146 
147 template <class T>
149  if (a == nullptr) return 0;
150  return a->size();
151 }
152 
153 template <class T>
155  if (a.empty()) return 0;
156  return a.size();
157 }
158 
159 template <class T>
160 int indexOf(T* arr, int n, const T& what) {
161  int isthereindex = -1;
162 
163  int i = 0;
164  while ((i < n) && (isthereindex == -1)) {
165  if (arr[i] == what) {
166  isthereindex = i;
167  };
168  i++;
169  };
170 
171  return isthereindex;
172 }
173 
174 template <class T>
175 void saveArrayOfArraysToFile(std::string fileName,
177  CVLog::PrintDebug("[IO] saveArrayOfArraysToFile: ", fileName.c_str());
178  FILE* f = fopen(fileName.c_str(), "wb");
179  int n = aa->size();
180  fwrite(&n, sizeof(int), 1, f);
181  for (int i = 0; i < n; i++) {
182  int m = 0;
183  StaticVector<T>* a = (*aa)[i];
184  if (a == NULL) {
185  fwrite(&m, sizeof(int), 1, f);
186  } else {
187  m = a->size();
188  fwrite(&m, sizeof(int), 1, f);
189  if (m > 0) {
190  fwrite(&(*a)[0], sizeof(T), m, f);
191  };
192  };
193  };
194  fclose(f);
195 }
196 
197 template <class T>
198 void saveArrayOfArraysToFile(const std::string fileName,
200  CVLog::PrintDebug("[IO] saveArrayOfArraysToFile: ", fileName.c_str());
201  FILE* f = fopen(fileName.c_str(), "wb");
202  int n = aa.size();
203  fwrite(&n, sizeof(int), 1, f);
204  for (int i = 0; i < n; i++) {
205  int m = 0;
206  StaticVector<T>& a = aa[i];
207  if (a.empty()) {
208  fwrite(&m, sizeof(int), 1, f);
209  } else {
210  m = a.size();
211  fwrite(&m, sizeof(int), 1, f);
212  if (m > 0) {
213  fwrite(&a[0], sizeof(T), m, f);
214  };
215  };
216  };
217  fclose(f);
218 }
219 
220 template <class T>
222  const std::string& fileName) {
223  CVLog::PrintDebug("[IO] loadArrayOfArraysFromFile: ", fileName.c_str());
224  FILE* f = fopen(fileName.c_str(), "rb");
225  if (f == nullptr) {
226  CVLog::Error("[IO] loadArrayOfArraysFromFile: can't open file ",
227  fileName.c_str());
228  }
229 
230  int n = 0;
231  size_t retval = fread(&n, sizeof(int), 1, f);
232  if (retval != 1) {
233  fclose(f);
234  CVLog::Error(
235  "[IO] loadArrayOfArraysFromFile: can't read outer array size");
236  }
238  aa->reserve(n);
239  aa->resize_with(n, NULL);
240  for (int i = 0; i < n; i++) {
241  int m = 0;
242  retval = fread(&m, sizeof(int), 1, f);
243  if (retval != 1) {
244  fclose(f);
245  CVLog::Error(
246  "[IO] loadArrayOfArraysFromFile: can't read inner array "
247  "size");
248  }
249  if (m > 0) {
250  StaticVector<T>* a = new StaticVector<T>();
251  a->resize(m);
252  retval = fread(&(*a)[0], sizeof(T), m, f);
253  if (retval != static_cast<std::size_t>(m)) {
254  fclose(f);
255  CVLog::Error(
256  "[IO] loadArrayOfArraysFromFile: can't read vector "
257  "element");
258  }
259  (*aa)[i] = a;
260  };
261  };
262  fclose(f);
263 
264  return aa;
265 }
266 
267 template <class T>
269  const std::string& fileName) {
270  CVLog::PrintDebug("[IO] loadArrayOfArraysFromFile: ", fileName.c_str());
271  FILE* f = fopen(fileName.c_str(), "rb");
272  if (f == nullptr) {
273  CVLog::Error("[IO] loadArrayOfArraysFromFile: can't open file ",
274  fileName.c_str());
275  }
276 
277  int n = 0;
278  size_t retval = fread(&n, sizeof(int), 1, f);
279  if (retval != 1) {
280  fclose(f);
281  CVLog::Error(
282  "[IO] loadArrayOfArraysFromFile: can't read outer array size");
283  }
284 
285  out_aa.reserve(n);
286  out_aa.resize(n);
287  for (int i = 0; i < n; i++) {
288  int m = 0;
289  retval = fread(&m, sizeof(int), 1, f);
290  if (retval != 1) {
291  fclose(f);
292  CVLog::Error(
293  "[IO] loadArrayOfArraysFromFile: can't read inner array "
294  "size");
295  }
296  if (m > 0) {
297  StaticVector<T>& a = out_aa[i];
298  a.resize(m);
299  retval = fread(&a[0], sizeof(T), m, f);
300  if (retval != static_cast<std::size_t>(m)) {
301  fclose(f);
302  CVLog::Error(
303  "[IO] loadArrayOfArraysFromFile: can't read vector "
304  "element");
305  }
306  };
307  };
308  fclose(f);
309 }
310 
311 template <class T>
312 void saveArrayToFile(const std::string& fileName,
313  const StaticVector<T>& a,
314  bool docompress = true) {
315  saveArrayToFile(fileName, &a, docompress);
316 }
317 
318 template <class T>
319 void saveArrayToFile(const std::string& fileName,
320  const StaticVector<T>* a,
321  bool docompress = true) {
322  CVLog::PrintDebug("[IO] saveArrayToFile: ", fileName.c_str());
323 
324  const std::string parent_dir =
326  if (!utility::filesystem::DirectoryExists(parent_dir)) {
328  }
329 
330  if (!a) {
332  "[IO] saveArrayToFile called with NULL static vector");
333  return;
334  }
335 
336  if (a->size() == 0) {
338  "[IO] saveArrayToFile called with 0-sized static vector");
339  return;
340  }
341 
342  if ((docompress == false) || (a->size() < 1000)) {
343  FILE* f = fopen(fileName.c_str(), "wb");
344  if (f == nullptr) {
345  CVLog::Error("[IO] file ", fileName.c_str(),
346  " could not be opened, msg: ", strerror(errno));
347  }
348  int n = a->size();
349  if (n == 0) {
350  fclose(f);
351  return;
352  }
353  auto items = fwrite(&n, sizeof(int), 1, f);
354  if (items < 1 && ferror(f) != 0) {
355  fclose(f);
356  CVLog::Error("[IO] failed to write 1 int to ", fileName.c_str(),
357  ", msg: ", strerror(errno));
358  }
359  items = fwrite(&(*a)[0], sizeof(T), n, f);
360  if (items < static_cast<std::size_t>(n) && ferror(f) != 0) {
361  fclose(f);
362  CVLog::Error("[IO] failed to write n items to ", fileName.c_str(),
363  ", msg: ", strerror(errno));
364  }
365  fclose(f);
366  } else {
367  /* ===========================================================================
368  //from zlib - compress.c
369  Compresses the source buffer into the destination buffer. The level
370  parameter has the same meaning as in deflateInit. sourceLen is the
371  byte length of the source buffer. Upon entry, destLen is the total size
372  of the destination buffer, which must be at least 0.1% larger than
373  sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the
374  compressed buffer.
375 
376  compress2 returns Z_OK if success, Z_MEM_ERROR if there was not
377  enough memory, Z_BUF_ERROR if there was not enough room in the output
378  buffer, Z_STREAM_ERROR if the level parameter is invalid.
379  */
380  // uLong comprLen = sizeof(T)*a->size();
381  uLong comprLen =
382  uLong(static_cast<double>(sizeof(T) * a->size()) * 1.02) + 12;
383  Byte* compr =
384  static_cast<Byte*>(calloc(static_cast<uInt>(comprLen), 1));
385  int err =
386  compress(compr, &comprLen, static_cast<const Bytef*>(&(*a)[0]),
387  sizeof(T) * a->size());
388 
389  if (err != Z_OK) {
390  CVLog::Error(QString("compress error %1 : 2% -> %3, n %4")
391  .arg(err, (sizeof(T) * a->size()), comprLen,
392  a->size()));
393 
394  FILE* f = fopen(fileName.c_str(), "wb");
395  if (f == nullptr) {
396  free(compr);
397  CVLog::Error("[IO] file ", fileName.c_str(),
398  " could not be opened, msg: ", strerror(errno));
399  }
400  int n = a->size();
401  if (n > 0) {
402  auto items = fwrite(&n, sizeof(int), 1, f);
403  if (items < 1 && ferror(f) != 0) {
404  fclose(f);
405  free(compr);
406  CVLog::Error("[IO] failed to write 1 int to ",
407  fileName.c_str(), ", msg: ", strerror(errno));
408  }
409  items = fwrite(&(*a)[0], sizeof(T), n, f);
410  if (items < 1 && ferror(f) != 0) {
411  fclose(f);
412  free(compr);
413  CVLog::Error(QString("[IO] failed to write %1 items to %2, "
414  "msg: %3")
415  .arg(QString::number(n),
416  fileName.c_str(),
417  strerror(errno)));
418  }
419  }
420  fclose(f);
421  } else {
422  FILE* f = fopen(fileName.c_str(), "wb");
423  if (f == nullptr) {
424  free(compr);
425  CVLog::Error("[IO] file ", fileName.c_str(),
426  " could not be opened, msg: ", strerror(errno));
427  }
428  int n = -1;
429  auto items = fwrite(&n, sizeof(int), 1, f);
430  if (items < 1 && ferror(f) != 0) {
431  fclose(f);
432  free(compr);
433  CVLog::Error("[IO] failed to write 1 int to ", fileName.c_str(),
434  ", msg: ", strerror(errno));
435  }
436  n = a->size();
437  items = fwrite(&n, sizeof(int), 1, f);
438  if (items < 1 && ferror(f) != 0) {
439  fclose(f);
440  free(compr);
441  CVLog::Error("[IO] failed to write 1 int to ", fileName.c_str(),
442  ", msg: ", strerror(errno));
443  }
444  items = fwrite(&comprLen, sizeof(uLong), 1, f);
445  if (items < 1 && ferror(f) != 0) {
446  fclose(f);
447  free(compr);
448  CVLog::Error("[IO] failed to write 1 uLong to ",
449  fileName.c_str(), ", msg: ", strerror(errno));
450  }
451  items = fwrite(compr, sizeof(Byte), comprLen, f);
452  if (items < 1 && ferror(f) != 0) {
453  fclose(f);
454  free(compr);
455  CVLog::Error(
456  QString("[IO] failed to write %1 items to %2, msg: %3")
457  .arg(QString::number(comprLen),
458  fileName.c_str(), strerror(errno)));
459  }
460  fclose(f);
461  };
462 
463  free(compr);
464  };
465 }
466 
467 template <class T>
468 StaticVector<T>* loadArrayFromFile(const std::string& fileName,
469  bool printfWarning = false) {
470  Q_UNUSED(printfWarning);
471  CVLog::PrintDebug("[IO] loadArrayFromFile: ", fileName.c_str());
472 
473  FILE* f = fopen(fileName.c_str(), "rb");
474  if (f == nullptr) {
475  CVLog::Error("loadArrayFromFile : can't open file ", fileName.c_str());
476  } else {
477  int n = 0;
478  size_t retval = fread(&n, sizeof(int), 1, f);
479  if (retval != 1) {
480  fclose(f);
481  CVLog::Error(
482  "[IO] loadArrayFromFile: can't read array size (1) from ",
483  fileName.c_str());
484  }
485  StaticVector<T>* a = NULL;
486 
487  if (n == -1) {
488  retval = fread(&n, sizeof(int), 1, f);
489  if (retval != 1) {
490  fclose(f);
491  CVLog::Error(
492  "[IO] loadArrayFromFile: can't read array size (2)");
493  }
494  a = new StaticVector<T>();
495  a->resize(n);
496 
497  uLong comprLen;
498  retval = fread(&comprLen, sizeof(uLong), 1, f);
499  if (retval != 1) {
500  delete a;
501  fclose(f);
502  CVLog::Error(
503  "[IO] loadArrayFromFile: can't read ulong elem size");
504  }
505  Byte* compr =
506  static_cast<Byte*>(calloc(static_cast<uInt>(comprLen), 1));
507  retval = fread(compr, sizeof(Byte), comprLen, f);
508  if (retval != comprLen) {
509  delete a;
510  fclose(f);
511  CVLog::Error("[IO] loadArrayFromFile: can't read blob");
512  }
513 
514  uLong uncomprLen = sizeof(T) * n;
515  int err = uncompress((Bytef*)(&(*a)[0]), &uncomprLen, compr,
516  comprLen);
517 
518  if (err != Z_OK) {
519  delete a;
520  fclose(f);
521  CVLog::Error(QString("uncompress error %1 : 2% -> %3, n %4")
522  .arg(QString::number(err),
523  QString::number(sizeof(T) * n),
524  QString::number(uncomprLen),
525  QString::number(n)));
526  }
527 
528  if (uncomprLen != sizeof(T) * n) {
529  delete a;
530  fclose(f);
531  CVLog::Error(
532  "loadArrayFromFile: uncompression failed "
533  "uncomprLen!=sizeof(T)*n");
534  }
535 
536  free(compr);
537  } else {
538  a = new StaticVector<T>();
539  a->resize(n);
540  size_t retval = fread(&(*a)[0], sizeof(T), n, f);
541  if (retval != static_cast<std::size_t>(n)) {
542  delete a;
543  fclose(f);
544  CVLog::Error("[IO] loadArrayFromFile: can't read n elements");
545  }
546  }
547 
548  fclose(f);
549 
550  return a;
551  }
552 }
553 
554 template <class T>
556  const std::string& fileName,
557  bool printfWarning = false) {
558  Q_UNUSED(printfWarning);
559  CVLog::PrintDebug("[IO] loadArrayFromFile: ", fileName.c_str());
560 
561  FILE* f = fopen(fileName.c_str(), "rb");
562  if (f == nullptr) {
563  throw std::runtime_error("loadArrayFromFile : can't open file " +
564  fileName);
565  } else {
566  int n = 0;
567  size_t retval = fread(&n, sizeof(int), 1, f);
568  if (retval != 1)
570  "[IO] loadArrayFromFile: can't read array size (1) from ",
571  fileName.c_str());
572  out.clear();
573 
574  if (n == -1) {
575  retval = fread(&n, sizeof(int), 1, f);
576  if (retval != 1)
578  "[IO] loadArrayFromFile: can't read array size (2)");
579  out.resize(n);
580 
581  uLong comprLen;
582  retval = fread(&comprLen, sizeof(uLong), 1, f);
583  if (retval != 1)
585  "[IO] loadArrayFromFile: can't read ulong elem size");
586  Byte* compr =
587  static_cast<Byte*>(calloc(static_cast<uInt>(comprLen), 1));
588  retval = fread(compr, sizeof(Byte), comprLen, f);
589  if (retval != comprLen)
590  CVLog::Warning("[IO] loadArrayFromFile: can't read blob");
591 
592  uLong uncomprLen = sizeof(T) * n;
593  int err = uncompress(
594  static_cast<Bytef*>(out.getDataWritable().data()),
595  &uncomprLen, compr, comprLen);
596 
597  if (err != Z_OK) {
598  CVLog::Error(QString("uncompress error %1 : 2% -> %3, n %4")
599  .arg(QString::number(err),
600  QString::number(sizeof(T) * n),
601  QString::number(uncomprLen),
602  QString::number(n)));
603  }
604 
605  if (uncomprLen != sizeof(T) * n) {
606  fclose(f);
607  throw std::runtime_error(
608  "loadArrayFromFile: uncompression failed "
609  "uncomprLen!=sizeof(T)*n");
610  }
611 
612  free(compr);
613  } else {
614  out.resize(n);
615  size_t retval =
616  fread(out.getDataWritable().data(), sizeof(T), n, f);
617  if (retval != static_cast<std::size_t>(n))
618  CVLog::Warning("[IO] loadArrayFromFile: can't read n elements");
619  }
620 
621  fclose(f);
622 
623  return true;
624  }
625 }
626 
627 template <class T>
629  const std::string& fileName,
630  bool printfWarning = false) {
631  Q_UNUSED(printfWarning);
632  CVLog::PrintDebug("[IO] loadArrayFromFileIntoArray: ", fileName.c_str());
633 
634  FILE* f = fopen(fileName.c_str(), "rb");
635  if (f == nullptr) {
636  CVLog::Error("loadArrayFromFileIntoArray: can not open file: ",
637  fileName.c_str());
638  }
639  int n = 0;
640  fread(&n, sizeof(int), 1, f);
641 
642  if (n == -1) {
643  fread(&n, sizeof(int), 1, f);
644  if (a->size() != n) {
645  fclose(f);
646  CVLog::Error("loadArrayFromFileIntoArray: expected length "
647  << a->size() << " loaded length " << n);
648  }
649 
650  uLong comprLen;
651  fread(&comprLen, sizeof(uLong), 1, f);
652  Byte* compr =
653  static_cast<Byte*>(calloc(static_cast<uInt>(comprLen), 1));
654  fread(compr, sizeof(Byte), comprLen, f);
655 
656  uLong uncomprLen = sizeof(T) * n;
657  int err = uncompress(static_cast<Bytef*>(&(*a)[0]), &uncomprLen, compr,
658  comprLen);
659 
660  if (err != Z_OK) {
661  fclose(f);
662  CVLog::Error(QString("uncompress error %1 : 2% -> %3, n %4")
663  .arg(QString::number(err),
664  QString::number(sizeof(T) * n),
665  QString::number(uncomprLen),
666  QString::number(n)));
667  }
668 
669  if (uncomprLen != sizeof(T) * n) {
670  fclose(f);
671  CVLog::Error(
672  "loadArrayFromFileIntoArray: uncompression failed "
673  "uncomprLen!=sizeof(T)*n");
674  }
675 
676  free(compr);
677  } else {
678  if (a->size() != n) {
679  fclose(f);
680  CVLog::Error("loadArrayFromFileIntoArray: expected length "
681  << a->size() << " loaded length " << n);
682  }
683  fread(&(*a)[0], sizeof(T), n, f);
684  }
685 
686  fclose(f);
687 }
688 
689 int getArrayLengthFromFile(std::string fileName);
690 
691 template <class T>
693  for (int i = 0; i < (*aa)->size(); i++) {
694  if ((*(*aa))[i] != nullptr) {
695  delete (*(*aa))[i];
696  (*(*aa))[i] = nullptr;
697  };
698  };
699  delete (*aa);
700 }
701 
702 template <class T>
704  for (int i = 0; i < aa.size(); i++) {
705  if (aa[i] != nullptr) {
706  delete aa[i];
707  aa[i] = nullptr;
708  };
709  };
710  aa.clear();
711 }
712 
713 template <class T>
715  StaticVector<StaticVector<T>*>* inAOA) {
716  StaticVector<StaticVector<T>*>* outAOA =
718  outAOA->reserve(inAOA->size());
719  // copy
720  for (int i = 0; i < inAOA->size(); i++) {
721  if ((*inAOA)[i] == NULL) {
722  outAOA->push_back(NULL);
723  } else {
724  StaticVector<T>* outA = new StaticVector<T>();
725  outA->reserve((*inAOA)[i]->size());
726  outA->push_back_arr((*inAOA)[i]);
727  outAOA->push_back(outA);
728  };
729  };
730 
731  return outAOA;
732 }
733 
734 } // namespace cloudViewer
#define CV_CORE_LIB_API
Definition: CVCoreLibWin.h:15
int size
#define NULL
static bool PrintDebug(const char *format,...)
Same as Print, but works only in Debug mode.
Definition: CVLog.cpp:153
static bool Warning(const char *format,...)
Prints out a formatted warning message in console.
Definition: CVLog.cpp:133
static bool Error(const char *format,...)
Display an error dialog with formatted message.
Definition: CVLog.cpp:143
void reserveAddIfNeeded(int nplanned, int ntoallocated)
Definition: StaticVector.h:73
int indexOf(const T &value) const
Definition: StaticVector.h:109
void assign(int n, T value)
Definition: StaticVector.h:69
T & operator[](int index)
Definition: StaticVector.h:43
const T & operator[](int index) const
Definition: StaticVector.h:41
int indexOfNearestSorted(const T &value) const
Definition: StaticVector.h:116
ConstIterator end() const
Definition: StaticVector.h:51
void push_back_arr(StaticVector< T > &arr)
Definition: StaticVector.h:91
void resize_with(int n, const T &val)
Definition: StaticVector.h:67
void swap(StaticVector &other)
Definition: StaticVector.h:68
int indexOfSorted(const T &value) const
Definition: StaticVector.h:114
const std::vector< T > & getData() const
Definition: StaticVector.h:59
void push_front(const T &val)
Definition: StaticVector.h:85
std::vector< T > & getDataWritable()
Definition: StaticVector.h:60
StaticVector(int n, const T &value)
Definition: StaticVector.h:39
ConstReference front() const
Definition: StaticVector.h:54
ConstIterator begin() const
Definition: StaticVector.h:50
void push_back_arr(StaticVector< T > *arr)
Definition: StaticVector.h:87
ConstReference back() const
Definition: StaticVector.h:57
void push_back(const T &val)
Definition: StaticVector.h:83
void reserveAdd(int ntoallocated)
Definition: StaticVector.h:79
void resize(int n, T value)
Definition: StaticVector.h:66
int push_back_distinct(const T &val)
Definition: StaticVector.h:97
size_t capacity() const
Definition: StaticVector.h:63
bool MakeDirectoryHierarchy(const std::string &directory)
Definition: FileSystem.cpp:499
std::string GetFileParentDirectory(const std::string &filename)
Definition: FileSystem.cpp:314
bool DirectoryExists(const std::string &directory)
Definition: FileSystem.cpp:473
Generic file read and write utility for python interface.
void deleteArrayOfArrays(StaticVector< StaticVector< T > * > **aa)
Definition: StaticVector.h:692
void saveArrayOfArraysToFile(std::string fileName, StaticVector< StaticVector< T > * > *aa)
Definition: StaticVector.h:175
int getArrayLengthFromFile(std::string fileName)
StaticVector< StaticVector< T > * > * loadArrayOfArraysFromFile(const std::string &fileName)
Definition: StaticVector.h:221
int indexOf(T *arr, int n, const T &what)
Definition: StaticVector.h:160
int sizeOfStaticVector(const StaticVector< T > *a)
Definition: StaticVector.h:148
StaticVector< T > * loadArrayFromFile(const std::string &fileName, bool printfWarning=false)
Definition: StaticVector.h:468
void loadArrayFromFileIntoArray(StaticVector< T > *a, const std::string &fileName, bool printfWarning=false)
Definition: StaticVector.h:628
void saveArrayToFile(const std::string &fileName, const StaticVector< T > &a, bool docompress=true)
Definition: StaticVector.h:312
StaticVector< StaticVector< T > * > * cloneArrayOfArrays(StaticVector< StaticVector< T > * > *inAOA)
Definition: StaticVector.h:714