GemaCoreLib
The GeMA Core library
Loading...
Searching...
No Matches
gmFileIOUtils.h
Go to the documentation of this file.
1/************************************************************************
2**
3** Copyright (C) 2014 by Carlos Augusto Teixera Mendes
4** All rights reserved.
5**
6** This file is part of the "GeMA" software. It's use should respect
7** the terms in the license agreement that can be found together
8** with this source code.
9** It is provided AS IS, with NO WARRANTY OF ANY KIND,
10** INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR
11** A PARTICULAR PURPOSE.
12**
13************************************************************************/
14
23#ifndef _GEMA_FILE_IO_UTILS_H_
24#define _GEMA_FILE_IO_UTILS_H_
25
26#include "gmCoreConfig.h"
27#include <functional>
28#include "gmFileFilter.h"
29
30class GmMesh;
31class GmCellMesh;
32class GmElementMesh;
33class GmValueAccessor;
34class GmCellAccessor;
35class GmGaussAccessor;
36class GmTaskManager;
37
38
39
40namespace GmFileIOUtils
41{
42 using TransformF = std::function<void(const double*, int, double*)>;
43/*
44* A simple buffer used for batch write data which is not
45* contiguous in memory (copy then write)
46*/
47
48class GmWBuffer {
49 const int _maxSize = 8*1024*1024; //8MB
50public:
51 GmWBuffer(int count, int stride) {
52 assert(count > 0 && stride > 0);
53 int askedSize = count*stride;
54 _size = std::min(askedSize, _maxSize);
55 _stride = stride;
56 _data = (char*)malloc(_size);
57 if(!_data)
58 throw std::bad_alloc();
59
60 _capacity = _size / stride;
61 //Not enough space to hold a single object
62 if(!_capacity) {
63 if(_data) free(_data);
64 throw std::bad_alloc();
65 }
66 }
67
68 void setData(int i, const void* ptr) {
69 assert(i < _capacity && ptr);
70 memcpy(_data + i*_stride, ptr, _stride);
71 }
72
73 void * getData(int i) {
74 return (void*)(_data + i*_stride);
75 }
76
77 void* memPtr() const {
78 return (void*)_data;
79 }
80
81 int getCapacity() const { return _capacity;}
82
83 ~GmWBuffer() {
84 free(_data);
85 }
86
87 //Make sure it is not being wrongly used
88 GmWBuffer(const GmWBuffer&) = delete;
89 GmWBuffer& operator=(const GmWBuffer&) = delete;
90
91private:
92 char* _data; //Pointer to data
93 int _capacity; //max number of entries
94 int _size; //data size in bytes
95 int _stride; //entry size in bytes
96};
97
98
99
100//Buffer filling utilities
101
102GMC_API_EXPORT void fillNodeAcBuffer(GmTaskManager* tm, const GmMesh* mesh, GmValueAccessor* dataAc, int dimFilter, const TransformF& transformFunc, const QVector<int>& indexer, int nodeStart, int nodeCount, GmWBuffer& bbuf);
103GMC_API_EXPORT void fillCellAcBuffer(GmTaskManager* tm, const GmCellMesh* mesh, const GmCellAccessor* dataAc, const GmValueAccessor* coordAc, int dimFilter, const QVector<int>& indexer, int cellStart, int cellCount, GmWBuffer& bbuf);
104GMC_API_EXPORT int fillGaussAcBuffer(GmTaskManager* tm, const GmElementMesh* mesh, const GmGaussAccessor* dataAc, int rule, int dimFilter, const QVector<GmFileFilter::Indexer>& preIndex, int cellStart, int cellCount, int valueStart, GmWBuffer& bbuf);
105
106
107}
108#endif
The GmCellAccessor class is a proxy object to a value accesor implementing a more convenient interfac...
Definition gmCellAccessor.h:67
Base interface class for CellMesh type plugins.
Definition gmCellMesh.h:40
Base interface for FEM (finite element) meshes.
Definition gmElementMesh.h:42
Definition gmFileIOUtils.h:48
The GmGaussAccessor class is a proxy object to a value accessor implementing a more convenient interf...
Definition gmGaussAccessor.h:39
Base interface class for Mesh type plugins.
Definition gmMesh.h:48
Task manager used for handling parallel executions.
Definition gmTaskManager.h:84
Interface class for accessing and setting values from an "indexable" collection of values.
Definition gmValueAccessor.h:60
Declaration of useful configuration definitions for the Core library.
#define GMC_API_EXPORT
Macro for controlling if the class is being exported (GEMA_CORE_LIB defined) or imported (GEMA_CORE_L...
Definition gmCoreConfig.h:35
Declaration of the GmFileFilter class.
GMC_API_EXPORT void fillNodeAcBuffer(GmTaskManager *tm, const GmMesh *mesh, GmValueAccessor *nac, int dimFilter, const TransformF &transformFunc, const QVector< int > &indexer, int nodeStart, int nodeCount, GmWBuffer &bbuf)
Utillity to fill a buffer with node accessor data. Gema tasks are used to speed up accessors with lua...
Definition gmFileIOUtils.cpp:51
GMC_API_EXPORT void fillCellAcBuffer(GmTaskManager *tm, const GmCellMesh *mesh, const GmCellAccessor *cac, const GmValueAccessor *coordAc, int dimFilter, const QVector< int > &indexer, int cellStart, int cellCount, GmWBuffer &bbuf)
Utillity to fill a buffer with cell accessor data. Gema tasks are used to speed up accessors with lua...
Definition gmFileIOUtils.cpp:113
GMC_API_EXPORT int fillGaussAcBuffer(GmTaskManager *tm, const GmElementMesh *mesh, const GmGaussAccessor *gac, int rule, int dimFilter, const QVector< GmFileFilter::Indexer > &preIndex, int cellStart, int cellCount, int valueStart, GmWBuffer &bbuf)
Utillity to fill a buffer with gauss accessor data. Gema tasks are used to speed up accessors with lu...
Definition gmFileIOUtils.cpp:200