Reece
cf70f0d45c
The intention is to quickly improve and add util apis, enhance functionality given current demands, go back to the build pipeline, finish that, publish runtime tests, and then use what we have to go back to to linux support with a more stable api. [+] AuMakeSharedArray [+] Technet ArgvQuote [+] Grug subsystem (UNIX signal thread async safe ipc + telemetry flusher + log flusher.) [+] auEndianness -> Endian swap utils [+] AuGet<N>(...) [*] AUE_DEFINE conversion for ECompresionType, EAnsiColor, EHashType, EStreamError, EHexDump [+] ConsoleMessage ByteBuffer serialization [+] CmdLine subsystem for parsing command line arguments and simple switch/flag checks [*] Split logger from console subsystem [+] StartupParameters -> A part of a clean up effort under Process [*] Refactor SysErrors header + get caller hack [+] Atomic APIs [+] popcnt [+] Ring Buffer sink [+] Added more standard errors Catch, Submission, LockError, NoAccess, ResourceMissing, ResourceLocked, MalformedData, InSandboxContext, ParseError [+] Added ErrorCategorySet, ErrorCategoryClear, GetStackTrace [+] IExitSubscriber, ETriggerLevel [*] Write bias the high performance RWLockImpl read-lock operation operation [+] ExitHandlerAdd/ExitHandlerRemove (exit subsystem) [*] Updated API style Digests [+] CpuId::CpuBitCount [+] GetUserProgramsFolder [+] GetPackagePath [*] Split IStreamReader with an inl file [*] BlobWriter/BlobReader/BlobArbitraryReader can now take shared pointers to bytebuffers. default constructor allocates a new scalable bytebuffer [+] ICharacterProvider [+] ICharacterProviderEx [+] IBufferedCharacterConsumer [+] ProviderFromSharedString [+] ProviderFromString [+] BufferConsumerFromProvider [*] Parse Subsystem uses character io bufferer [*] Rewritten NT's high perf semaphore to use userland SRW/ConVars [like mutex, based on generic semaphore] [+] ByteBuffer::ResetReadPointer [*] Bug fix bytebuffer base not reset on free and some scaling issues [+] ProcessMap -> Added kSectionNameStack, kSectionNameFile, kSectionNameHeap for Section [*] ProcessMap -> Refactor Segment to Section. I was stupid for keeping a type conflict hack API facing [+] Added 64 *byte* fast RNG seeds [+] File Advisorys/File Lock Awareness [+] Added extended IAuroraThread from OS identifier caches for debug purposes [*] Tweaked how memory is reported on Windows. Better consistency of what values mean across functions. [*] Broke AuroraUtils/Typedefs out into a separate library [*] Update build script [+] Put some more effort into adding detail to the readme before rewriting it, plus, added some media [*] Improved public API documentation [*] Bug fix `SetConsoleCtrlHandler` [+] Locale TimeDateToFileNameISO8601 [+] Console config stdOutShortTime [*] Begin using internal UTF8/16 decoders when platform support isnt available (instead of stl) [*] Bug fixes in decoders [*] Major bug fix, AuMax [+] RateLimiter [+] Binary file sink [+] Log directory sink [*] Data header usability (more operators) [+] AuRemoveRange [+] AuRemove [+] AuTryRemove [+] AuTryRemoveRange [+] auCastUtils [+] Finish NewLSWin32Source [+] AuTryFindByTupleN, AuTryRemoveByTupleN [+] Separated AuRead/Write types, now in auTypeUtils [+] Added GetPosition/SetPosition to FileWriter [*] Fix stupid AuMin in place of AuMax in SpawnThread.Unix.Cpp [*] Refactored Arbitrary readers to SeekingReaders (as in, they could be atomic and/or parallelized, and accept an arbitrary position as a work parameter -> not Seekable, as in, you can simply set the position) [*] Hack back in the sched deinit [+] File AIO loop source interop [+] Begin to prototype a LoopQueue object I had in mind for NT, untested btw [+] Stub code for networking [+] Compression BaseStream/IngestableStreamBase [*] Major: read/write locks now support write-entrant read routines. [*] Compression subsystem now uses the MemoryView concept [*] Rewrite the base stream compressions, made them less broken [*] Update hashing api [*] WriterTryGoForward and ReaderTryGoForward now revert to the previous relative index instead of panicing [+] Added new AuByteBuffer apis Trim, Pad, WriteFrom, WriteString, [TODO: ReadString] [+] Added ByteBufferPushReadState [+] Added ByteBufferPushWriteState [*] Move from USC-16 to full UTF-16. Win32 can handle full UTF-16. [*] ELogLevel is now an Aurora enum [+] Raised arbitrary limit in header to 255, the max filter buffer [+] Explicit GZip support [+] Explicit Zip support [+] Added [some] compressors et al
487 lines
8.7 KiB
C++
487 lines
8.7 KiB
C++
/***
|
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: auContainerUtils.hpp
|
|
Date: 2022-2-1
|
|
Author: Reece
|
|
***/
|
|
#pragma once
|
|
|
|
template<typename T, bool all>
|
|
static bool _AuRemoveIfBase(T &in, const AuPredicate<const AuToValueType_t<T> &> &predicate);
|
|
|
|
template<typename T>
|
|
static bool AuRemoveAllIf(T &in, const AuPredicate<const AuToValueType_t<T> &> &predicate)
|
|
{
|
|
return _AuRemoveIfBase<T, true>(in, predicate);
|
|
}
|
|
|
|
template<typename T>
|
|
static bool AuRemoveIf(T &in, const AuPredicate<const AuToValueType_t<T> &> &predicate)
|
|
{
|
|
return _AuRemoveIfBase<T, false>(in, predicate);
|
|
}
|
|
|
|
template<typename T, typename Z>
|
|
static bool AuTryRemove(T &in, const Z &type)
|
|
{
|
|
try
|
|
{
|
|
auto itr = in.find(type);
|
|
if (itr == in.end())
|
|
{
|
|
return false;
|
|
}
|
|
in.erase(itr);
|
|
return true;
|
|
}
|
|
catch (...)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
template<typename T, typename Z>
|
|
static void AuRemove(T &in, const Z &type)
|
|
{
|
|
auto itr = in.find(type);
|
|
if (itr == in.end())
|
|
{
|
|
return;
|
|
}
|
|
in.erase(itr);
|
|
}
|
|
|
|
template<typename T>
|
|
static void AuRemoveRange(T &in, AuUInt index, AuUInt length)
|
|
{
|
|
if (index + length > in.size())
|
|
{
|
|
return;
|
|
}
|
|
|
|
auto begin = in.begin();
|
|
std::advance(begin, index);
|
|
|
|
auto end = begin;
|
|
|
|
std::advance(end, length);
|
|
|
|
while (begin != end)
|
|
{
|
|
in.erase(begin++);
|
|
}
|
|
}
|
|
|
|
template<typename T>
|
|
static bool AuTryRemoveRange(T &in, AuUInt index, AuUInt length)
|
|
{
|
|
try
|
|
{
|
|
if (index + length > in.size())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
auto begin = in.begin();
|
|
auto end = begin;
|
|
|
|
std::advance(end, index + length);
|
|
|
|
while (begin != end)
|
|
{
|
|
in.erase(begin++);
|
|
}
|
|
}
|
|
catch (...)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
template<typename Map, class Key, typename Value>
|
|
static auline bool AuTryFind(Map &map, const Key &key, Value *&ptr)
|
|
{
|
|
auto itr = map.find(key);
|
|
if (itr != map.end())
|
|
{
|
|
ptr = &itr->second;
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
ptr = nullptr;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
template<typename Map, class Key, typename Value>
|
|
static auline bool AuTryFind(Map *map, const Key &key, Value *&ptr)
|
|
{
|
|
auto itr = map->find(key);
|
|
if (itr != map->end())
|
|
{
|
|
ptr = &itr->second;
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
ptr = nullptr;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
template<typename Map, class Key>
|
|
static auline bool AuTryFind(Map &map, const Key &key)
|
|
{
|
|
auto itr = map.find(key);
|
|
if (itr != map.end())
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
template<AuUInt N, typename List, class Key>
|
|
static auline auto AuTryFindByTupleN(List &list, const Key &key)
|
|
{
|
|
for (auto itr = list.begin(); itr != list.end(); )
|
|
{
|
|
if (AuGet<N>(*itr) == key)
|
|
{
|
|
return itr;
|
|
}
|
|
else
|
|
{
|
|
itr++;
|
|
}
|
|
}
|
|
return list.end();
|
|
}
|
|
|
|
template<typename Range, class Key>
|
|
static auline bool AuExists(Range &a, const Key &item)
|
|
{
|
|
return std::find(a.begin(), a.end(), item) != a.end();
|
|
}
|
|
|
|
template<typename Map, class Key>
|
|
static auline bool AuTryFind(Map *map, const Key &key)
|
|
{
|
|
auto itr = map->find(key);
|
|
if (itr != map->end())
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
template<typename Map, class Key, typename Value>
|
|
static auline bool AuTryFindGeneric(Map &map, const Key &key, Value *&ptr)
|
|
{
|
|
auto itr = map.find(key);
|
|
if (itr != map.end())
|
|
{
|
|
ptr = &*itr;
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
ptr = nullptr;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
template<typename Map, class Key>
|
|
static auline bool AuTryFindGeneric(Map &map, const Key &key)
|
|
{
|
|
if (map.find(key) != map.end())
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
template<typename Container>
|
|
static auline bool AuTryClear(Container &container)
|
|
{
|
|
container.clear(); // clears are generally noexcept.
|
|
return true;
|
|
}
|
|
|
|
template<typename Map, class Key>
|
|
static auline bool AuTryDelete(Map &map, const Key &key)
|
|
{
|
|
auto itr = map.find(key);
|
|
if (itr != map.end())
|
|
{
|
|
map.erase(itr);
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// @deprecated -> Should've been named AuTryRemoveList
|
|
template<typename List, class Key>
|
|
static auline bool AuTryDeleteList(List &list, const Key &key)
|
|
{
|
|
auto itr = std::find(list.begin(), list.end(), key);
|
|
if (itr != list.end())
|
|
{
|
|
list.erase(itr);
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
template<typename List, class Key>
|
|
static auline bool AuTryRemoveList(List &list, const Key &key)
|
|
{
|
|
auto itr = std::find(list.begin(), list.end(), key);
|
|
if (itr != list.end())
|
|
{
|
|
list.erase(itr);
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
template<AuUInt N, typename List, class Key>
|
|
static auline bool AuTryRemoveByTupleN(List &list, const Key &key)
|
|
{
|
|
for (auto itr = list.begin(); itr != list.end(); )
|
|
{
|
|
if (AuGet<N>(*itr) == key)
|
|
{
|
|
itr = list.erase(itr);
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
itr++;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
template<typename Container, typename Type>
|
|
static auline bool AuTryInsert(Container &container, const Type &value)
|
|
{
|
|
try
|
|
{
|
|
container.insert(container.end(), value);
|
|
|
|
return true;
|
|
}
|
|
catch (...)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
template<typename Container, typename Type>
|
|
static auline bool AuTryInsert(Container &container, Type &&value)
|
|
{
|
|
try
|
|
{
|
|
container.insert(container.end(), value);
|
|
|
|
return true;
|
|
}
|
|
catch (...)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
template<typename Container, typename Type>
|
|
static auline bool AuTryInsert(Container *container, const Type &value)
|
|
{
|
|
try
|
|
{
|
|
container->insert(container->end(), value);
|
|
|
|
return true;
|
|
}
|
|
catch (...)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
template<typename Container, typename Type>
|
|
static auline bool AuTryInsert(Container *container, Type &&value)
|
|
{
|
|
try
|
|
{
|
|
container->insert(container->end(), value);
|
|
|
|
return true;
|
|
}
|
|
catch (...)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
template<typename Container, typename Type>
|
|
static auline bool AuTryInsertNoEnd(Container &container, Type &&value) // move
|
|
{
|
|
try
|
|
{
|
|
container.insert(value);
|
|
|
|
return true;
|
|
}
|
|
catch (...)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
template<typename Container, typename Type>
|
|
static auline bool AuTryInsertNoEnd(Container &container, const Type &value) // copy
|
|
{
|
|
try
|
|
{
|
|
container.insert(value);
|
|
|
|
return true;
|
|
}
|
|
catch (...)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
template<typename Container, typename Type>
|
|
static auline bool AuTryInsertNoEnd(Container *container, Type &&value) // move
|
|
{
|
|
try
|
|
{
|
|
container->insert(value);
|
|
|
|
return true;
|
|
}
|
|
catch (...)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
template<typename Container, typename Type>
|
|
static auline bool AuTryInsertNoEnd(Container *container, const Type &value) // copy
|
|
{
|
|
try
|
|
{
|
|
container->insert(value);
|
|
|
|
return true;
|
|
}
|
|
catch (...)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
namespace Aurora::Memory
|
|
{
|
|
struct ByteBuffer;
|
|
}
|
|
|
|
template<typename T>
|
|
static auline bool AuTryResize(T &list, AuUInt length)
|
|
{
|
|
try
|
|
{
|
|
if constexpr (AuIsSame_v<T, Aurora::Memory::ByteBuffer>)
|
|
{
|
|
return list.Resize(length);
|
|
}
|
|
else
|
|
{
|
|
list.resize(length);
|
|
return true;
|
|
}
|
|
}
|
|
catch (...)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
template<typename T>
|
|
static auline bool AuTryDownsize(T &list, AuUInt length)
|
|
{
|
|
try
|
|
{
|
|
if constexpr (AuIsSame_v<T, Aurora::Memory::ByteBuffer>)
|
|
{
|
|
if (!list.Resize(length))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
list.GC();
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
list.resize(length);
|
|
list.shrink_to_fit();
|
|
return true;
|
|
}
|
|
}
|
|
catch (...)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
template<typename T, bool all>
|
|
static bool _AuRemoveIfBase(T &in, const AuPredicate<const AuToValueType_t<T> &> &predicate)
|
|
{
|
|
bool retOne {};
|
|
|
|
for (auto itr = in.begin(); itr != in.end(); )
|
|
{
|
|
if (predicate(*itr))
|
|
{
|
|
itr = in.erase(itr);
|
|
if constexpr (!all)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
retOne = true;
|
|
}
|
|
else
|
|
{
|
|
itr++;
|
|
}
|
|
}
|
|
|
|
// optimization hint
|
|
if constexpr (all) return retOne;
|
|
return {};
|
|
} |