Peano
Loading...
Searching...
No Matches
DataSet.cpp
Go to the documentation of this file.
1#include "DataSet.h"
2
3#include <string>
4#include <vector>
5#include <iostream>
6#include <fstream>
7#include <algorithm>
8
9#include "tarch/Assertions.h"
10
11
12tarch::logging::Log convert::data::DataSet::_log( "convert::data::DataSet" );
13
14
17
18
20 for (auto& p: data) {
21 logDebug( "free()", "free data set " << p.first.name );
22 for (auto& pp: p.second) {
23 pp.free();
24 }
25 }
26}
27
28
29std::vector<convert::data::PatchData> convert::data::DataSet::getData( const Variable& selector ) const {
30 if ( data.count(selector)==0) {
31 logError( "createReaders(...)", "no data set with identifier " << selector.name );
32 return std::vector<convert::data::PatchData>();
33 }
34 else {
35 return data.at(selector);
36 }
37}
38
39
41 for (const auto& p: other.data) {
42 if ( data.count(p.first)==0 ) {
43 data.insert( std::pair< Variable, std::vector<PatchData> >(
44 p.first, p.second
45 ));
46 }
47 else {
48 for (const auto& pp: other.getData(p.first)) {
49 data[p.first].push_back(pp);
50 }
51 }
52 }
53}
54
55
56std::vector<convert::data::Variable> convert::data::DataSet::getVariables() const {
57 std::vector<convert::data::Variable> result;
58 for (auto p: data) {
59 result.push_back(p.first);
60 }
61 return result;
62}
63
64
65bool convert::data::DataSet::hasVariable( const std::string& name ) const {
66 for (auto& p: data) {
67 if (p.first.name==name) {
68 return true;
69 }
70 }
71 return false;
72}
73
74
76 const convert::data::Variable* result;
77 for (auto& p: data) {
78 if (p.first.name==name) {
79 result = &(p.first);
80 }
81 }
82 return *result;
83}
84
85
86void convert::data::DataSet::add( Variable variable, const std::vector<PatchData>& patchData ) {
87 assertion( data.count(variable)==0 );
88
89 data.insert( std::pair< convert::data::Variable, std::vector<convert::data::PatchData> >(
90 variable, patchData
91 ));
92}
#define assertion(expr)
#define logError(methodName, logMacroMessageStream)
Wrapper macro around tarch::tarch::logging::Log to improve logging.
Definition Log.h:464
#define logDebug(methodName, logMacroMessageStream)
Definition Log.h:50
A dataset is a wrapper around one big map.
Definition DataSet.h:34
std::vector< Variable > getVariables() const
Definition DataSet.cpp:56
Variable getVariable(const std::string &name) const
Definition DataSet.cpp:75
static tarch::logging::Log _log
Definition DataSet.h:68
std::map< Variable, std::vector< PatchData > > data
Definition DataSet.h:70
std::vector< PatchData > getData(const Variable &selector) const
Definition DataSet.cpp:29
bool hasVariable(const std::string &name) const
Definition DataSet.cpp:65
void add(Variable variable, const std::vector< PatchData > &patchData)
If you add a patch, don't free the patch, i.e.
Definition DataSet.cpp:86
void merge(const DataSet &other)
This operation does not do a deep copy, i.e.
Definition DataSet.cpp:40
Represents one variable that is subsequently attached to the patches of a file.
Definition Variable.h:18
const std::string name
Definition Variable.h:22
Log Device.
Definition Log.h:516