Core: LoadFromFile, StoreToFile Event variant

git-svn-id: svn://ultimatepp.org/upp/trunk@11385 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2017-10-16 12:07:32 +00:00
parent 9d85fb1680
commit f916d286f1
5 changed files with 36 additions and 3 deletions

View file

@ -26,6 +26,7 @@ struct Heap {
32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384,
448, 576, 672, 800, 992, 8, 16, 24, 40, 48, 56
// 12 13 14 15 16 17 18 19 20 21 22
// 8 - 56 sizes are only available with TinyAlloc
};
static_assert(__countof(sz) == 23, "NKLASS mismatch");
return sz[k];

View file

@ -682,6 +682,19 @@ void SetGlobalConfigData(const char *name, const String& data)
sGCfg().GetAdd(name) = data;
}
bool LoadFromGlobal(Event<Stream&> x, const char *name)
{
StringStream ss(GetGlobalConfigData(name));
return ss.IsEof() || Load(x, ss);
}
void StoreToGlobal(Event<Stream&> x, const char *name)
{
StringStream ss;
Store(x, ss);
SetGlobalConfigData(name, ss);
}
void SerializeGlobalConfigs(Stream& s)
{
Mutex::Lock __(sGCfgLock);

View file

@ -472,6 +472,9 @@ void StoreToGlobal(T& x, const char *name)
SetGlobalConfigData(name, ss);
}
bool LoadFromGlobal(Event<Stream&> serialize, const char *name);
void StoreToGlobal(Event<Stream&> serialize, const char *name);
void SerializeGlobalConfigs(Stream& s);
#ifdef PLATFORM_WINCE

View file

@ -189,13 +189,29 @@ has to be explicitly triggered before storing configuration.&]
[s5;:LoadFromGlobal`(T`&`,const char`*`):%- [@(0.0.255) template]_<[@(0.0.255) class]_[*@4 T
][@(0.0.255) >]_[@(0.0.255) bool]_[* LoadFromGlobal]([*@4 T][@(0.0.255) `&]_[*@3 x],
[@(0.0.255) const]_[@(0.0.255) char]_`*[*@3 name])&]
[s2; Loads [%-*@3 x] from global configuration key [%-*@3 name].&]
[s2; Loads [%-*@3 x] from global configuration key [%-*@3 name], using
Serialize method of T.&]
[s3; &]
[s4;%- &]
[s5;:StoreToGlobal`(T`&`,const char`*`):%- [@(0.0.255) template]_<[@(0.0.255) class]_[*@4 T
][@(0.0.255) >]_[@(0.0.255) void]_[* StoreToGlobal]([*@4 T][@(0.0.255) `&]_[*@3 x],
[@(0.0.255) const]_[@(0.0.255) char]_`*[*@3 name])&]
[s2; Stores [@3 x] to global configuration key [%-*C@3 name].&]
[s2; Stores [@3 x] to global configuration key [%-*@3 name], using Serialize
method of T.&]
[s3; &]
[s4;%- &]
[s5;:Upp`:`:LoadFromGlobal`(Upp`:`:Event`<Upp`:`:Stream`&`>`,const char`*`):%- [@(0.0.255) b
ool]_[* LoadFromGlobal]([_^Upp`:`:Event^ Event]<Stream[@(0.0.255) `&]>_[*@3 serialize],
[@(0.0.255) const]_[@(0.0.255) char]_`*[*@3 name])&]
[s2; Loads [%-*@3 x] from global configuration key [%-*@3 name], using
[%-*@3 serialize] as serialization function.&]
[s3; &]
[s4;%- &]
[s5;:Upp`:`:StoreToGlobal`(Upp`:`:Event`<Upp`:`:Stream`&`>`,const char`*`):%- [@(0.0.255) v
oid]_[* StoreToGlobal]([_^Upp`:`:Event^ Event]<Stream[@(0.0.255) `&]>_[*@3 x],
[@(0.0.255) const]_[@(0.0.255) char]_`*[*@3 name])&]
[s2; Stores [@3 x] to global configuration key [%-*@3 name], using [%-*@3 serialize]
as serialization function.&]
[s3; &]
[s4;%- &]
[s5;:SerializeGlobalConfigs`(Stream`&`):%- [@(0.0.255) void]_[* SerializeGlobalConfigs]([_^Stream^ S

View file

@ -45,7 +45,7 @@ _[*@3 fr])&]
[s2;%% Replaces multiple patterns with replace texts. When patterns
and replaces are specified by VectorMap, keys are patterns. Text
replaced is not searched for more instances of patterns. Longest
pattern is always used (if patterns:replases are `"hell`":`"hello`"
pattern is always used (if patterns:replaces are `"hell`":`"hello`"
and `"hello`":`"hell`", then replacing within `"hell hello`" produces
`"hello hell`").&]
[s3;%% &]