langsmoke/ref_cpp

59 lines
2.6 KiB
Plaintext
Raw Normal View History

2023-11-12 18:29:17 +00:00
#include <iostream>
#include <string>
#include <vector>
<map> <fstream> <sstream> <iomanip> <algorithm> <numeric> <functional> <iterator> <memory> <utility> <stdexcept> <typeinfo> <exception> <locale>
<cmath> <complex> <valarray> <bitset> <queue> <stack> <deque> <list> <set> <map> <unordered_set> <unordered_map> <forward_list> <array> <tuple>
new switch auto else operator template break enum private this case extern protected throw
catch public try char for typedef class friend return union const short unsigned continue if signed virtual
default inline sizeof void delete int static volatile do long struct while
template <typename T>
struct has_process {
template <typename U>
static auto test(U* p) -> decltype(std::declval<U>().process(), std::true_type());
template <typename U>
static std::false_type test(...);
static constexpr bool value = decltype(test<T>(nullptr))::value;
2023-11-12 17:29:29 +00:00
};
2023-11-12 18:29:17 +00:00
inline BOOL DecodeOneFile(FILE* fpIn)
{
char WrkStr[260];
int MaxOrder, SASize;
BOOL CutOff;
if ( !fread(&ai,sizeof(ai),1,fpIn) ) return FALSE;
CutOff=ai.FNLen >> 14;
ai.FNLen=CLAMP(int(ai.FNLen & 0x1FF),1,260-1);
fread(WrkStr,ai.FNLen,1,fpIn); WrkStr[ai.FNLen]=0;
if ( !TestAccessRare(WrkStr) ) return FALSE;
FILE* fpOut = FOpen(pFName=WrkStr,"wb");
MaxOrder=(ai.info & 0x0F)+1; SASize=((ai.info >> 4) & 0xFF)+1;
DWORD Variant=(ai.info >> 12)+'A';
if (ai.signature != PPMdSignature || Variant != PROG_VAR) {
printf(MTxt[0],WrkStr); exit(-1);
}
PrepareCoding(SASize,fpIn); DecodeFile(fpOut,fpIn,MaxOrder,CutOff);
putchar('\n');
if (ferror(fpOut) || ferror(fpIn) || feof(fpIn)) {
printf(MTxt[1],WrkStr,WrkStr); exit(-1);
}
fclose(fpOut); EnvSetDateTimeAttr(WrkStr);
return TRUE;
}
template <typename T, typename Predicate, typename Consumer>
std::enable_if_t<std::is_same_v<function_return_type<Consumer>, void>>
find_all(T begin, T end, Predicate pred, Consumer consumer) {
T iter = begin;
while ((iter = std::find_if(iter, end, pred)) != end)
consumer(iter), iter++;
}
template <typename T, typename Predicate, typename Consumer,
class = typename std::enable_if<!std::is_same_v<function_return_type<Consumer>, void>>::type>
std::vector<function_return_type<Consumer>>
find_all(T begin, T end, Predicate pred, Consumer consumer) {
T iter = begin;
std::vector<function_return_type<Consumer>> data;
while ((iter = std::find_if(iter, end, pred)) != end)
data.push_back(consumer(iter)), iter++;
return data;
2023-11-12 13:49:57 +00:00
}