OWLNext
7.0
Borland's Object Windows Library for the modern age
Toggle main menu visibility
Loading...
Searching...
No Matches
strmresid.h
Go to the documentation of this file.
1
//----------------------------------------------------------------------------
2
// ObjectWindows
3
//
4
/// \file
5
/// Private helper for reading resource identifiers from persistent streams.
6
//----------------------------------------------------------------------------
7
8
#ifndef OWL_STRMRESID_H
9
#define OWL_STRMRESID_H
10
11
#include <
owl/private/defs.h
>
12
#if defined(BI_HAS_PRAGMA_ONCE)
13
# pragma once
14
#endif
15
16
#include <
owl/defs.h
>
17
#include <
owl/wsyscls.h
>
18
#include <memory>
19
#include <set>
20
21
#if defined(BI_MULTI_THREAD_RTL)
22
#include <
owl/thread.h
>
23
#endif
24
25
namespace
owl
{
26
27
//
28
// Takes ownership of a resource identifier just extracted from a persistent stream, and returns
29
// an equivalent identifier that does not need to be deallocated.
30
//
31
// The persistent stream extraction operator for TResId allocates a new string when the identifier
32
// is a string, leaving the caller responsible for deallocating it. Many members that store
33
// resource identifiers do not own the string (e.g. TWindow::Attr.AccelTable, TMenuDescr::Id),
34
// so here the string is moved into a process-lifetime pool instead, in which equal strings are
35
// shared. Hence, repeated reads of the same identifiers do not use any more memory. See bug #156.
36
//
37
inline
auto
InternStreamedResId_
(
TResId
id
) ->
TResId
38
{
39
if
(!
id
.IsString())
return
id;
40
const
auto
s = std::unique_ptr<tchar[]>{
const_cast<
tchar
*
>
(
id
.GetString())};
41
static
std::set<tstring> pool;
42
#if defined(BI_MULTI_THREAD_RTL)
43
static
TCriticalSection
section;
44
TCriticalSection::TLock
lock{section};
45
#endif
46
return
TResId
{pool.insert(
tstring
{s.get()}).first->c_str()};
47
}
48
49
}
// OWL namespace
50
51
#endif
// OWL_STRMRESID_H
owl::TCriticalSection::TLock
This nested class handles locking and unlocking critical sections.
Definition
thread.h:326
owl::TCriticalSection
Lightweight intra-process thread synchronization.
Definition
thread.h:308
owl::TResId
Definition
wsyscls.h:206
owl
Object Windows Library (OWLNext Core).
Definition
animctrl.h:22
owl::tchar
char tchar
Definition
defs.h:77
owl::tstring
std::string tstring
Definition
defs.h:79
owl::InternStreamedResId_
auto InternStreamedResId_(TResId id) -> TResId
Definition
strmresid.h:37
defs.h
General definitions used by all ObjectWindows programs.
defs.h
thread.h
wsyscls.h
Classes for window system structure and type encapsulation.
source
owlcore
strmresid.h
Generated by
1.18.0