-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from UniStuttgart-VISUS/collector
Improved collector
- Loading branch information
Showing
9 changed files
with
417 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
power_overwhelming/include/power_overwhelming/collector.inl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// <copyright file="collector.inl" company="Visualisierungsinstitut der Universität Stuttgart"> | ||
// Copyright © 2023 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. | ||
// </copyright> | ||
// <author>Christoph Müller</author> | ||
|
||
|
||
/* | ||
* visus::power_overwhelming::collector::from_sensor_lists | ||
*/ | ||
template<class... TSensorLists> | ||
visus::power_overwhelming::collector | ||
visus::power_overwhelming::collector::from_sensor_lists( | ||
TSensorLists&&... sensors) { | ||
std::array<std::vector<std::unique_ptr<sensor>>, | ||
sizeof...(sensors)> instances = { move_to_heap(sensors)... }; | ||
|
||
const auto cnt = std::accumulate(instances.begin(), | ||
instances.end(), static_cast<std::size_t>(0), | ||
[](const std::size_t s, const decltype(instances)::value_type& v) { | ||
return std::size(v) + s; | ||
}); | ||
|
||
auto retval = collector::prepare(cnt); | ||
|
||
for (auto& l : instances) { | ||
for (auto& i : l) { | ||
// See 'from_sensors' for the rationale of this. | ||
retval.add(i.release()); | ||
} | ||
} | ||
|
||
return retval; | ||
} | ||
|
||
/* | ||
* visus::power_overwhelming::collector::from_sensors | ||
*/ | ||
template<class... TSensors> | ||
visus::power_overwhelming::collector | ||
visus::power_overwhelming::collector::from_sensors(TSensors&&... sensors) { | ||
std::array<std::unique_ptr<sensor>, sizeof...(sensors)> instances = { | ||
std::unique_ptr<sensor>(new typename std::decay<TSensors>::type( | ||
std::move(sensors)))... | ||
}; | ||
|
||
auto retval = collector::prepare(instances.size()); | ||
|
||
for (auto& i : instances) { | ||
// Note: We release this on purpose as the library and the calling code | ||
// might have been compiled with different versions of the STL. The | ||
// unique_ptr here is only for releasing the memory in case of | ||
// an exeception. | ||
retval.add(i.release()); | ||
} | ||
|
||
return retval; | ||
} | ||
|
||
|
||
/* | ||
* visus::power_overwhelming::collector::move_to_heap | ||
*/ | ||
template<class TSensorList> | ||
std::vector<std::unique_ptr<visus::power_overwhelming::sensor>> | ||
visus::power_overwhelming::collector::move_to_heap(TSensorList&& sensors) { | ||
typedef typename std::decay<decltype(sensors.front())>::type sensor_type; | ||
|
||
decltype(move_to_heap(sensors)) retval; | ||
retval.reserve(std::size(sensors)); | ||
|
||
std::transform(sensors.begin(), sensors.end(), std::back_inserter(retval), | ||
[](typename sensor_type& s) { | ||
return std::unique_ptr<sensor>(new typename sensor_type(std::move(s))); | ||
}); | ||
|
||
return retval; | ||
} |
44 changes: 44 additions & 0 deletions
44
power_overwhelming/include/power_overwhelming/regex_escape.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// <copyright file="regex_escape.h" company="Visualisierungsinstitut der Universität Stuttgart"> | ||
// Copyright © 2023 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. | ||
// </copyright> | ||
// <author>Christoph Müller</author> | ||
|
||
#pragma once | ||
|
||
#include <algorithm> | ||
#include <regex> | ||
|
||
#include "power_overwhelming/literal.h" | ||
|
||
|
||
namespace visus { | ||
namespace power_overwhelming { | ||
|
||
/// <summary> | ||
/// Escape all special characters in the given string such that they match | ||
/// as literals in a regular expression. | ||
/// </summary> | ||
/// <typeparam name="TChar">The character type.</typeparam> | ||
/// <param name="str">The string to match literally in a regular expression. | ||
/// </param> | ||
/// <returns>The escaped string.</returns> | ||
template<class TChar> | ||
std::basic_string<TChar> regex_escape(const std::basic_string<TChar>& str) { | ||
static const std::basic_string<TChar> special | ||
= POWER_OVERWHELMING_TPL_LITERAL(TChar, "-[]{}()*+?.,\\^$|#"); | ||
std::basic_string<TChar> retval; | ||
retval.reserve(str.size() + str.size() / 3); // Just a heuristic ... | ||
|
||
for (auto c : str) { | ||
if (special.find(c) != decltype(special)::npos) { | ||
retval += POWER_OVERWHELMING_TPL_LITERAL(TChar, "\\"); | ||
} | ||
|
||
retval += c; | ||
} | ||
|
||
return retval; | ||
} | ||
|
||
} /* namespace power_overwhelming */ | ||
} /* namespace visus */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.