OWLNext    7.0
Borland's Object Windows Library for the modern age
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
13namespace owl {
14
15//
16/// Initialize the data members to 0.
17//
23
24//
25/// Walk the heap chain & delete the memory blocks
26//
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//
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//
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//
81{
82 for (TRegItem* regItem = Items; regItem->Key != nullptr; regItem++) {
83 if (strcmp(regItem->Key, key) == 0)
84 return regItem->Value;
85 }
87}
88
89//
90// Maximum string length for REGFORMAT w/ string arg. String is clipped if too
91// long.
92//
93const int MaxFormatLen = 40;
94
95//
96/// Registers data formats for the object.
97//
98//
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//
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//
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//
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/* ========================================================================== */
Used internally to provide buffers for formating registration strings.
Definition registry.h:484
~TRegFormatHeap()
Walk the heap chain & delete the memory blocks.
Definition regheap.cpp:27
tchar * Alloc(int spaceNeeded)
Allocate a block of memory of a given size & link it into the heap chain.
Definition regheap.cpp:39
TRegFormatHeap()
Initialize the data members to 0.
Definition regheap.cpp:18
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
TRegItem * Items
Definition registry.h:547
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
#define _stprintf
Definition cygwin.h:88
#define _T(x)
Definition cygwin.h:51
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
owl::uint16 TLangId
Holds a language ID, a predefined number that represents a base language and dialect.
Definition lclstrng.h:26
const int MaxFormatLen
Definition regheap.cpp:93
General Registry access & registration implementation TRegKey, TRegValue, TRegKeyIterator,...
Designed to provide support for localized registration parameters, the TLocaleString Struct defines a...
Definition lclstrng.h:68
static TLocaleString Null
reference a null string
Definition lclstrng.h:94
A single registration list entry.
Definition registry.h:508
static tchar * RegFormat(int f, int a, int t, int d, TRegFormatHeap &heap)
Registers data formats for the object.
Definition regheap.cpp:99
static tchar * RegFlags(long flags, TRegFormatHeap &heap)
Registers the flag.
Definition regheap.cpp:132
static tchar * RegVerbOpt(int mf, int sf, TRegFormatHeap &heap)
Registers the verb option.
Definition regheap.cpp:148