OWLNext
7.0
Borland's Object Windows Library for the modern age
Toggle main menu visibility
Loading...
Searching...
No Matches
regheap.cpp
Go to the documentation of this file.
1
//----------------------------------------------------------------------------
2
// ObjectWindows
3
// Copyright (c) 1994, 1996 by Borland International, All Rights Reserved
4
//
5
/// \file
6
/// TRegItem and TRegList members that need to be linked into user app and not
7
/// the WinSys DLL
8
//----------------------------------------------------------------------------
9
#include <
owl/pch.h
>
10
#include <
owl/registry.h
>
11
#include <stdio.h>
// sprintf()
12
13
namespace
owl
{
14
15
//
16
/// Initialize the data members to 0.
17
//
18
TRegFormatHeap::TRegFormatHeap
()
19
:
20
Head(nullptr)
21
{
22
}
23
24
//
25
/// Walk the heap chain & delete the memory blocks
26
//
27
TRegFormatHeap::~TRegFormatHeap
()
28
{
29
while
(Head) {
30
TBlock* next = Head->Next;
31
delete
[] (
tchar
*)Head;
32
Head = next;
33
}
34
}
35
36
//
37
/// Allocate a block of memory of a given size & link it into the heap chain
38
//
39
LPTSTR
TRegFormatHeap::Alloc
(
int
spaceNeeded)
40
{
41
TBlock* newblock = (TBlock*)
new
tchar
[
sizeof
(TBlock) + spaceNeeded];
42
newblock->Next = Head;
43
Head = newblock;
44
45
return
newblock->Data;
46
}
47
48
//
49
/// Performs the lookup of the TRegItems using a key (an item name such as progid)
50
/// and returns the value associated with the key (for example, "My Sample
51
/// Application"). The value is returned in the language specified in lang (for
52
/// example, French Canadian).
53
///
54
/// Returns an empty string if there is no associated value.
55
///
56
/// If the key does not exist, it returns a null pointer.
57
//
58
LPCTSTR
TRegList::Lookup
(LPCSTR key,
TLangId
lang)
59
{
60
if
(key) {
61
for
(
TRegItem
* regItem =
Items
; regItem->
Key
!=
nullptr
; regItem++) {
62
if
(strcmp(regItem->Key, key) == 0)
63
{
64
if
(regItem->Value.Private)
// current can't test Value directly
65
return
regItem->Value.Translate(lang);
66
else
67
return
_T
(
""
);
68
}
69
}
70
}
71
return
nullptr
;
72
}
73
74
//
75
//
76
/// Looks up and returns a reference to a local string value associated with a
77
/// particular item name (key). You can then translate this string into the local
78
/// language as necessary.
79
//
80
TLocaleString
&
TRegList::LookupRef
(LPCSTR key)
81
{
82
for
(
TRegItem
* regItem =
Items
; regItem->
Key
!=
nullptr
; regItem++) {
83
if
(strcmp(regItem->Key, key) == 0)
84
return
regItem->Value;
85
}
86
return
TLocaleString::Null
;
87
}
88
89
//
90
// Maximum string length for REGFORMAT w/ string arg. String is clipped if too
91
// long.
92
//
93
const
int
MaxFormatLen
= 40;
94
95
//
96
/// Registers data formats for the object.
97
//
98
//
99
LPTSTR
TRegItem::RegFormat
(
int
f,
int
a,
int
t,
int
d,
TRegFormatHeap
& heap)
100
{
101
// sprintf into sized auto buffer
102
// ints have a max of 11 digits: -2000000000. Add pad of 8 just in case
103
//
104
tchar
temp[11+1+11+1+11+1+11+1+8];
105
int
len =
_stprintf
(temp,
_T
(
"%d,%d,%d,%d"
), f, a, t, d);
106
107
// Copy into real heap buffer & return it
108
//
109
return ::_tcscpy(heap.
Alloc
(len + 1), temp);
110
}
111
112
//
113
//
114
/// Registers data formats for the object.
115
//
116
LPTSTR
TRegItem::RegFormat
(LPCTSTR f,
int
a,
int
t,
int
d,
TRegFormatHeap
& heap)
117
{
118
// _stprintf into sized auto buffer
119
//
120
tchar
temp[
MaxFormatLen
+1+11+1+11+1+11+1+8];
121
int
len =
_stprintf
(temp,
_T
(
"%.*s,%d,%d,%d"
),
MaxFormatLen
, (LPTSTR)f, a, t, d);
122
123
// Copy into real heap buffer & return it
124
//
125
return ::_tcscpy(heap.
Alloc
(len + 1), temp);
126
}
127
128
//
129
/// Registers the flag.
130
//
131
//
132
LPTSTR
TRegItem::RegFlags
(
long
flags,
TRegFormatHeap
& heap)
133
{
134
// _stprintf into sized auto buffer
135
//
136
tchar
temp[11+1+8];
137
int
len =
_stprintf
(temp,
_T
(
"%ld"
), flags);
138
139
// Copy into real heap buffer & return it
140
//
141
return ::_tcscpy(heap.
Alloc
(len + 1), temp);
142
}
143
144
//
145
/// Registers the verb option.
146
//
147
//
148
LPTSTR
TRegItem::RegVerbOpt
(
int
mf,
int
sf,
TRegFormatHeap
& heap)
149
{
150
// _stprintf into sized auto buffer
151
//
152
tchar
temp[11+1+11+1+8];
153
int
len =
_stprintf
(temp,
_T
(
"%d,%d"
), mf, sf);
154
155
// Copy into real heap buffer & return it
156
//
157
return ::_tcscpy(heap.
Alloc
(len + 1), temp);
158
}
159
160
}
// OWL namespace
161
/* ========================================================================== */
owl::TRegFormatHeap
Used internally to provide buffers for formating registration strings.
Definition
registry.h:484
owl::TRegFormatHeap::~TRegFormatHeap
~TRegFormatHeap()
Walk the heap chain & delete the memory blocks.
Definition
regheap.cpp:27
owl::TRegFormatHeap::Alloc
tchar * Alloc(int spaceNeeded)
Allocate a block of memory of a given size & link it into the heap chain.
Definition
regheap.cpp:39
owl::TRegFormatHeap::TRegFormatHeap
TRegFormatHeap()
Initialize the data members to 0.
Definition
regheap.cpp:18
owl::TRegList::LookupRef
TLocaleString & LookupRef(LPCSTR key)
Looks up and returns a reference to a local string value associated with a particular item name (key)...
Definition
regheap.cpp:80
owl::TRegList::Items
TRegItem * Items
Definition
registry.h:547
owl::TRegList::Lookup
LPCTSTR Lookup(LPCSTR key, TLangId lang=TLocaleString::UserDefaultLangId)
Performs the lookup of the TRegItems using a key (an item name such as progid) and returns the value ...
Definition
regheap.cpp:58
_stprintf
#define _stprintf
Definition
cygwin.h:88
_T
#define _T(x)
Definition
cygwin.h:51
pch.h
owl
Object Windows Library (OWLNext Core).
Definition
animctrl.h:22
owl::TLangId
owl::uint16 TLangId
Holds a language ID, a predefined number that represents a base language and dialect.
Definition
lclstrng.h:26
owl::tchar
char tchar
Definition
defs.h:77
owl::MaxFormatLen
const int MaxFormatLen
Definition
regheap.cpp:93
registry.h
General Registry access & registration implementation TRegKey, TRegValue, TRegKeyIterator,...
owl::TLocaleString
Designed to provide support for localized registration parameters, the TLocaleString Struct defines a...
Definition
lclstrng.h:68
owl::TLocaleString::Null
static TLocaleString Null
reference a null string
Definition
lclstrng.h:94
owl::TRegItem
A single registration list entry.
Definition
registry.h:508
owl::TRegItem::Key
const char * Key
Non-localized parameter or registry subkey.
Definition
registry.h:509
owl::TRegItem::RegFormat
static tchar * RegFormat(int f, int a, int t, int d, TRegFormatHeap &heap)
Registers data formats for the object.
Definition
regheap.cpp:99
owl::TRegItem::RegFlags
static tchar * RegFlags(long flags, TRegFormatHeap &heap)
Registers the flag.
Definition
regheap.cpp:132
owl::TRegItem::RegVerbOpt
static tchar * RegVerbOpt(int mf, int sf, TRegFormatHeap &heap)
Registers the verb option.
Definition
regheap.cpp:148
source
owlcore
regheap.cpp
Generated by
1.18.0