29 template <
bool B,
typename InputType>
30 auto tryDereference(InputType& arg) ->
typename std::enable_if_t<B, decltype(*arg) &> {
35 template <
bool B,
typename InputType>
36 auto tryDereference(InputType&& arg) ->
typename std::enable_if_t<!B, InputType&> {
41 template <
bool B,
typename InputType>
43 return InputType::getObjectSize();
47 template <
bool B,
typename InputType>
49 return sizeof(InputType);
53 template <
bool B,
typename InputType>
59 template <
bool B,
typename InputType>
76 std::function<void*(void*, std::vector<bool>&)>
filter;
79 std::function<void*(void*, std::vector<uint32_t>&)>
replicate;
88 std::function<void(Handle<Vector<Handle<Object>>>&,
void*,
size_t&)>
writeToVector;
107 std::function<
void(
void*)>
deleter,
108 std::function<
void*(
void*, std::vector<bool>&)>
filter,
109 std::function<
void*(
void*, std::vector<uint32_t>&)>
replicate,
110 std::function<
size_t(
void*)>
getCount,
122 typeContained(typeContained),
123 mustDelete(mustDelete),
124 serializedSize(serializedSize) {}
135 std::map<int, std::pair<void*, MaintenanceFuncs>>
columns;
157 std::vector<std::string> output;
158 for (
int i = 0;
columns.count(i) != 0; i++) {
159 output.push_back(
columns[i].second.typeContained);
178 template <
typename ColType>
180 if (
columns.count(whichColumn) == 0) {
181 std::cout <<
"This is bad. Tried to get column " << whichColumn
182 <<
" but could not find it.\n";
184 return *((std::vector<ColType>*)
columns[whichColumn].
first);
192 bool startFromScratch) {
193 if (
columns.count(whichColumn) == 0) {
194 std::cout <<
"This is bad. Tried to write out column " << whichColumn
195 <<
" but could not find it.\n";
197 auto& which =
columns[whichColumn];
200 if (startFromScratch)
201 which.second.lastWritten = 0;
203 which.second.writeToVector(writeToMe, which.first, which.second.lastWritten);
209 return columns[whichColToOutput].second.createPDBVector();
214 return columns.count(whichColumn) != 0;
221 auto& res = a.second;
222 if (res.second.mustDelete)
223 res.second.deleter(res.first);
234 auto& value =
columns[whichColToFilter];
235 auto res = value.second.filter(value.first, usingMe);
238 if (value.second.mustDelete) {
239 value.second.deleter(value.first);
246 value.second.mustDelete =
true;
250 std::cout <<
"This is really bad... trying to filter a non-existing column";
256 int whichColInFromMe,
257 int whichColToCopyTo,
258 std::vector<uint32_t>& replications) {
263 auto& value =
columns[whichColToCopyTo];
264 if (value.second.mustDelete) {
265 value.second.deleter(value.first);
270 auto& value = fromMe->columns[whichColInFromMe];
277 void* newCol = temp.
replicate(value.first, replications);
280 columns[whichColToCopyTo] = std::make_pair(newCol, temp);
300 auto& value =
columns[whichColToCopyTo];
301 if (value.second.mustDelete) {
302 value.second.deleter(value.first);
307 auto& value = fromMe->columns[whichColInFromMe];
314 columns[whichColToCopyTo] = std::make_pair(value.first, temp);
318 template <
typename ColType>
319 void addColumn(
int where, std::vector<ColType>* addMe,
bool needToDelete) {
322 if (
columns.count(where) != 0) {
324 if (value.second.mustDelete) {
325 value.second.deleter(value.first);
332 std::function<void(void*)>
deleter;
333 deleter = [](
void* deleteMe) {
334 std::vector<ColType>* killMe = (std::vector<ColType>*)deleteMe;
340 std::function<void*(void*, std::vector<bool>&)>
filter;
341 filter = [](
void*
filter, std::vector<bool>& whichAreValid) {
342 std::vector<ColType>& filterMe = *((std::vector<ColType>*)filter);
346 for (
auto a : whichAreValid)
351 std::vector<ColType>* newVec =
new std::vector<ColType>(counter);
353 for (
int i = 0; i < filterMe.size(); i++) {
354 if (whichAreValid[i])
355 (*newVec)[counter++] = filterMe[i];
359 return (
void*)newVec;
361 std::function<void*(void*, std::vector<uint32_t>&)>
replicate;
364 std::vector<ColType>& replicateMe = *((std::vector<ColType>*)replicate);
368 for (
auto& a : timesToReplicate)
372 std::vector<ColType>* newVec =
new std::vector<ColType>(counter);
374 for (
int i = 0; i < timesToReplicate.size(); i++) {
375 for (
int j = 0; j < timesToReplicate[i]; j++) {
376 (*newVec)[counter] = replicateMe[i];
382 return (
void*)newVec;
385 std::function<size_t(void*)> getCount;
386 getCount = [](
void* countMe) {
387 std::vector<ColType>* toCountRowsOfMe = (std::vector<ColType>*)countMe;
388 return toCountRowsOfMe->size();
392 std::function<void(Handle<Vector<Handle<Object>>>&,
void*,
size_t&)> writeToVector;
393 if (std::is_base_of<PtrBase, ColType>::value)
396 std::vector<Ptr<Handle<Object>>>& writeMeOut =
397 *((std::vector<Ptr<Handle<Object>>>*)writeMe);
399 for (; lastWritten < writeMeOut.size(); lastWritten++) {
401 outputToMe.
push_back(*(writeMeOut[lastWritten]));
407 std::vector<Handle<Object>>& writeMeOut = *((std::vector<Handle<Object>>*)writeMe);
409 for (; lastWritten < writeMeOut.size(); lastWritten++) {
410 outputToMe.
push_back(writeMeOut[lastWritten]);
416 std::function<Handle<Vector<Handle<Object>>>()> createPDBVector;
417 createPDBVector = []() {
419 return unsafeCast<Vector<Handle<Object>>>(returnVal);
430 getTypeName<ColType>(),
432 columns[where] = std::make_pair((
void*)addMe, myFuncs);
bool hasColumn(int whichColumn)
int getNumRows(int whichColumn)
Handle< Vector< Handle< Object > > > getOutputVector(int whichColToOutput)
std::function< void *(void *, std::vector< bool > &)> filter
std::vector< ColType > & getColumn(int whichColumn)
std::function< void(Handle< Vector< Handle< Object >>> &, void *, size_t &)> writeToVector
MaintenanceFuncs(std::function< void(void *)> deleter, std::function< void *(void *, std::vector< bool > &)> filter, std::function< void *(void *, std::vector< uint32_t > &)> replicate, std::function< size_t(void *)> getCount, std::function< Handle< Vector< Handle< Object >>>()> createPDBVector, std::function< void(Handle< Vector< Handle< Object >>> &, void *, size_t &)> writeToVector, bool mustDelete, std::string typeContained, size_t serializedSize)
void deleter(void *deleteMe, ObjType *dummy)
auto tryDereference(InputType &arg) -> typename std::enable_if_t< B, decltype(*arg)& >
std::vector< std::string > getTypeNames()
void writeOutColumn(int whichColumn, Handle< Vector< Handle< Object >>> &writeToMe, bool startFromScratch)
std::function< void(void *)> deleter
PolicyList< OtherPolicies...>::type first()
void addColumn(int where, std::vector< ColType > *addMe, bool needToDelete)
auto getSerializedSize() -> typename std::enable_if_t< B, size_t >
std::shared_ptr< TupleSet > TupleSetPtr
void filterColumn(int whichColToFilter, std::vector< bool > &usingMe)
std::function< size_t(void *)> getCount
std::function< void *(void *, std::vector< uint32_t > &)> replicate
std::string typeContained
void filter(std::string &r, const char *b)
std::function< Handle< Vector< Handle< Object > > >)> createPDBVector
void push_back(const TypeContained &val)
void replicate(TupleSetPtr fromMe, int whichColInFromMe, int whichColToCopyTo, std::vector< uint32_t > &replications)
std::map< int, std::pair< void *, MaintenanceFuncs > > columns
auto tryToObtainPointer(InputType &arg) -> typename std::enable_if_t< B, InputType * >
void copyColumn(TupleSetPtr fromMe, int whichColInFromMe, int whichColToCopyTo)