Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mumble-voip/mumble.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavide Beatrici <git@davidebeatrici.dev>2020-11-06 23:37:06 +0300
committerDavide Beatrici <git@davidebeatrici.dev>2020-11-06 23:37:06 +0300
commit988b8417acfc4ca4b19283afe7e1973d05a39be8 (patch)
tree160e79e9d7dc57ac27e02279775ea29418a537ae /plugins/mumble_plugin_utils.h
parenta3480a2a6b432b247821add175f725714692ef1e (diff)
REFAC(positional-audio): Proper functions/classes for module-related operations
Previously, only module() was present: it retrieved the base address of the specified module. It worked fine, but it iterated through the process' modules every time it was called. This commit replaces it with modules(), which returns an std::unordered_map containing all modules. The map uses the module name as key and Module as value. Aside from the performance improvement, the new code also provides info for each module region: - Start address. - Size. - Whether it's readable, writable and/or executable.
Diffstat (limited to 'plugins/mumble_plugin_utils.h')
-rw-r--r--plugins/mumble_plugin_utils.h32
1 files changed, 32 insertions, 0 deletions
diff --git a/plugins/mumble_plugin_utils.h b/plugins/mumble_plugin_utils.h
index fb82cbca1..260b0b20a 100644
--- a/plugins/mumble_plugin_utils.h
+++ b/plugins/mumble_plugin_utils.h
@@ -10,6 +10,7 @@
#include <codecvt>
#include <fstream>
#include <locale>
+#include <sstream>
#ifdef OS_LINUX
# include <fenv.h>
@@ -118,6 +119,37 @@ static inline std::string readFile(const std::string &path) {
return content;
}
+/// Reads characters from the stream until \p character is encountered.
+/// @return Read characters and whether the stream is still good.
+static inline std::pair< std::string, bool > readUntil(std::stringstream &stream,
+ const std::stringstream::int_type character) {
+ std::string buf;
+
+ for (auto input = stream.get(); input != character; input = stream.get()) {
+ if (!stream) {
+ return { buf, false };
+ }
+
+ buf.push_back(input);
+ };
+
+ return { buf, true };
+}
+
+/// Discards characters in the stream until the specified one is encountered.
+/// @param[inverted] Inverts the behavior.
+/// @return Whether the stream is still good.
+static inline bool skipUntil(std::stringstream &stream, const std::stringstream::int_type character,
+ const bool inverted) {
+ for (auto input = stream.get(); inverted ? (input == character) : (input != character); input = stream.get()) {
+ if (!stream) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
/// Calculates sine and cosine of the specified value.
/// On Linux the calculation is guaranteed to be simultaneous.
static inline bool sinCos(const float value, float &outSin, float &outCos) {