8000 Namespaced classes for better portability. · coderforlife/pe-file@03036dd · GitHub
[go: up one dir, main page]

Skip to content

Commit 03036dd

Browse files
committed
Namespaced classes for better portability.
1 parent a39c74e commit 03036dd

13 files changed

+146
-103
lines changed

PEFile.cpp

Lines changed: 72 additions & 69 deletions
Large diffs are not rendered by default.

PEFile.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
#define WIN32_LEAN_AND_MEAN
88
#include <Windows.h>
99

10+
namespace PE {
11+
1012
#define LARGE_PATH 32767
1113

12-
class PEFile {
14+
class File {
1315
protected:
1416
IMAGE_DOS_HEADER *dosh;
1517
LONG peOffset;
@@ -39,9 +41,9 @@ class PEFile {
3941
bool load(bool incRes);
4042
void unload();
4143
public:
42-
PEFile(LPVOID data, size_t size, bool readonly = false); // data is freed when the PEFile is deleted
43-
PEFile(LPCWSTR filename, bool readonly = false);
44-
~PEFile();
44+
File(LPVOID data, size_t size, bool readonly = false); // data is freed when the PEFile is deleted
45+
File(LPCWSTR filename, bool readonly = false);
46+
~File();
4547
bool isLoaded() const;
4648
bool isReadOnly() const;
4749

@@ -120,3 +122,5 @@ class PEFile {
120122
static VS_FIXEDFILEINFO *GetVersionInfo(const LPVOID ver);
121123
static void UnmapAllViewsOfFile(LPCWSTR file);
122124
};
125+
126+
}

PEFileResources.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
#pragma unmanaged
66
#endif
77

8+
using namespace PE;
9+
using namespace ustl;
10+
811
// Raised when resources have a problem loading
912
class ResLoadFailure {};
1013
static ResLoadFailure resLoadFailure;

PEFileResources.h

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class Rsrc;
2222
#define WIN32_LEAN_AND_MEAN
2323
#include <Windows.h>
2424

25+
namespace PE {
26+
2527
// Functions / Macros used by both PEFile and PEFileResources
2628
#define RESID2WORD(ID) ((WORD)((ULONG_PTR)(ID)))
2729
template<unsigned int MULT> inline static size_t roundUpTo(size_t x) { size_t mod = x % MULT; return (mod == 0) ? x : (x + MULT - mod); }
@@ -42,12 +44,6 @@ class Resource {
4244
virtual size_t getThisHeaderSize() const = 0;
4345
};
4446

45-
// Forward Declarations
46-
//class ResourceLang;
47-
//class ResourceName;
48-
//class ResourceType;
49-
//class Rsrc;
50-
5147
// The final resource directory, contains the data for the resource
5248
class ResourceLang : Resource {
5349
friend class ResourceName;
@@ -77,7 +73,7 @@ class ResourceLang : Resource {
7773
void writeRESData(LPBYTE data, size_t& pos, LPCWSTR type, LPCWSTR name) const;
7874
};
7975

80-
typedef map<WORD, ResourceLang*> LangMap;
76+
typedef ustl::map<WORD, ResourceLang*> LangMap;
8177

8278
// The named resource directory, the second level
8379
class ResourceName : Resource {
@@ -105,7 +101,7 @@ class ResourceName : Resource {
105101
ResourceLang* operator[](WORD lang);
106102
const ResourceLang* operator[](WORD lang) const;
107103

108-
vector<WORD> getLangs() const;
104+
ustl::vector<WORD> getLangs() const;
109105

110106
private:
111107
bool cleanup();
@@ -119,7 +115,7 @@ class ResourceName : Resource {
119115
void writeRESData(LPBYTE data, size_t& pos, LPCWSTR type) const;
120116
};
121117

122-
typedef map<LPWSTR, ResourceName*, ResCmp> NameMap;
118+
typedef ustl::map<LPWSTR, ResourceName*, ResCmp> NameMap;
123119

124120
// The typed resource directory, the first level
125121
class ResourceType : Resource {
@@ -147,8 +143,8 @@ class ResourceType : Resource {
147143
ResourceName* operator[](LPCWSTR name);
148144
const ResourceName* operator[](LPCWSTR name) const;
149145

150-
vector<LPCWSTR> getNames() const;
151-
vector<WORD> getLangs(LPCWSTR name) const;
146+
ustl::vector<LPCWSTR> getNames() const;
147+
ustl::vector<WORD> getLangs(LPCWSTR name) const;
152148

153149
private:
154150
bool cleanup();
@@ -163,7 +159,7 @@ class ResourceType : Resource {
163159
void writeRESData(LPBYTE data, size_t& pos) const;
164160
};
165161

166-
typedef map<LPWSTR, ResourceType*, ResCmp> TypeMap;
162+
typedef ustl::map<LPWSTR, ResourceType*, ResCmp> TypeMap;
167163

168164
class Rsrc : Resource {
169165
TypeMap types;
@@ -192,9 +188,9 @@ class Rsrc : Resource {
192188
ResourceType* operator[](LPCWSTR type);
193189
const ResourceType* operator[](LPCWSTR type) const;
194190

195-
vector<LPCWSTR> getTypes() const;
196-
vector<LPCWSTR> getNames(LPCWSTR type) const;
197-
vector<WORD> getLangs(LPCWSTR type, LPCWSTR name) const;
191+
ustl::vector<LPCWSTR> getTypes() const;
192+
ustl::vector<LPCWSTR> getNames(LPCWSTR type) const;
193+
ustl::vector<WORD> getLangs(LPCWSTR type, LPCWSTR name) const;
198194

199195
bool cleanup();
200196
LPVOID compile(size_t* size, DWORD startVA); // calls cleanup
@@ -207,4 +203,6 @@ class Rsrc : Resource {
207203
virtual size_t getRESSize() const;
208204
};
209205

206+
}
207+
210208
#endif

ufunction.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
#pragma once
66

7+
#include <string.h>
8+
9+
namespace ustl {
10+
711
//----------------------------------------------------------------------
812
// Standard functors
913
//----------------------------------------------------------------------
@@ -55,8 +59,9 @@ STD_UNARY_FUNCTOR (identity, T, (a))
5559
template <class T1, class T2> struct project1st : public binary_function<T1,T2,T1> { inline const T1& operator()(const T1& a, const T2&) const { return (a); } };
5660
template <class T1, class T2> struct project2nd : public binary_function<T1,T2,T2> { inline const T2& operator()(const T1&, const T2& a) const { return (a); } };
5761

58-
#include <string.h>
5962
template<> class less<char*> { public: inline bool operator()(const char*& a, const char*& b) const { return strcmp(a, b) < 0; } };
6063
//template<> class less<LPCSTR> { public: inline bool operator()(const LPCSTR& a, const LPCSTR& b) const { return strcmp(a, b) < 0; } };
6164
template<> class less<wchar_t*> { public: inline bool operator()(const wchar_t*& a, const wchar_t*& b) const { return wcscmp(a, b) < 0; } };
6265
//template<> class less<LPCWSTR> { public: inline bool operator()(const LPCWSTR& a, const LPCWSTR& b) const { return wcscmp(a, b) < 0; } };
66+
67+
}

uiterator.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
#include "utypes.h"
88

9+
namespace ustl {
10+
911
template <typename Iterator>
1012
struct iterator_traits {
1113
typedef typename Iterator::value_type value_type;
@@ -62,3 +64,5 @@ class reverse_iterator {
6264
protected:
6365
Iterator i;
6466
};
67+
68+
}

ulimits.h

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
#include "utypes.h"
88

9+
namespace ustl {
10+
911
#define __limits_digits(T) (sizeof(T)*8)
1012

1113
template <typename T>
@@ -20,23 +22,23 @@ struct numeric_limits {
2022

2123
template <typename T>
2224
struct numeric_limits<T*> {
23-
static inline T* min() { return NULL; }
24-
static inline T* max() { return reinterpret_cast<T*>(UINTPTR_MAX); }
25-
static const bool is_signed = false;
26-
static const bool is_integer = true;
27-
static const bool is_integral = true;
28-
static const unsigned digits = __limits_digits(T*);
25+
static inline T* min() { return NULL; }
26+
static inline T* max() { return reinterpret_cast<T*>(UINTPTR_MAX); }
27+
static const bool is_signed = false;
28+
static const bool is_integer = true;
29+
static const bool is_integral = true;
30+
static const unsigned digits = __limits_digits(T*);
2931
};
3032

3133
#define NUMERIC_LIMITS(T, minVal, maxVal, bSigned, bInteger, bIntegral) \
3234
template <> \
3335
struct numeric_limits<T> { \
34-
static inline T min() { return minVal; } \
35-
static inline T max() { return maxVal; } \
36-
static const bool is_signed = bSigned; \
37-
static const bool is_integer = bInteger; \
38-
static const bool is_integral = bIntegral; \
39-
static const unsigned digits = __limits_digits(T); \
36+
static inline T min() { return minVal; } \
37+
static inline T max() { return maxVal; } \
38+
static const bool is_signed = bSigned; \
39+
static const bool is_integer = bInteger; \
40+
static const bool is_integral = bIntegral; \
41+
static const unsigned 10000 digits = __limits_digits(T); \
4042
}
4143

4244
//--------------------------------------------------------------------------------------
@@ -59,3 +61,5 @@ NUMERIC_LIMITS( long double, LDBL_MIN, LDBL_MAX, true, false, true);
5961
NUMERIC_LIMITS( long long, LLONG_MIN, LLONG_MAX, true, true, true);
6062
NUMERIC_LIMITS( unsigned long long, 0, ULLONG_MAX, false, true, true);
6163
//--------------------------------------------------------------------------------------
64+
65+
}

umap.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include "upair.h"
1212
#include "ufunction.h"
1313

14+
namespace ustl {
15+
1416
template <typename K, typename T, typename Compare = less<K> >
1517
class map : protected vector<pair<K,T> > {
1618
public:
@@ -168,3 +170,5 @@ inline typename map<K,V,Compare>::const_iterator map<K,V,Compare>::upper_bound(c
168170
}
169171
return last;
170172
}
173+
174+
}

umemory.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include "uiterator.h"
1515
#include "ulimits.h"
1616

17+
namespace ustl {
18+
1719
template <typename T>
1820
class CDA2 auto_ptr {
1921
public:
@@ -83,3 +85,5 @@ inline void destroy (ForwardIterator first, ForwardIterator last) throw() {
8385
typedef typename iterator_traits<ForwardIterator>::value_type value_type;
8486
Sdtorsr<ForwardIterator,numeric_limits<value_type>::is_integral>()(first, last);
8587
}
88+
89+
}

upair.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
#include "utypes.h"
88

9+
namespace ustl {
10+
911
template <typename T1, typename T2>
1012
class pair {
1113
public:
@@ -30,3 +32,5 @@ inline bool operator==(const pair<T1,T2>& a, const pair<T1,T2>& b) { return a.fi
3032

3133
template <typename T1, typename T2>
3234
inline bool operator<(const pair<T1,T2>& a, const pair<T1,T2>& b) { return a.first < b.first || a.first == b.first && a.second < b.second; }
35+
36+
}

utypes.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ typedef _W64 int ssize_t;
3131
#endif
3232
#endif
3333

34+
namespace ustl {
35+
3436
typedef size_t uoff_t; ///< A type for storing offsets into blocks measured by size_t.
3537
typedef uint32_t hashvalue_t; ///< Value type returned by the hash functions.
3638
typedef size_t streamsize; ///< Size of stream data
3739
typedef uoff_t streamoff; ///< Offset into a stream
40+
41+
}

uutility.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include "ulimits.h"
1010
#include <assert.h>
1111

12+
namespace ustl {
13+
1214
template <typename T1, typename T2> inline T1 min(const T1& a, const T2& b) { return (a < b ? a : b); }
1315
template <typename T1, typename T2> inline T1 max(const T1& a, const T2& b) { return (b < a ? a : b); }
1416

@@ -45,3 +47,4 @@ template <typename T> inline bool operator!=(const T& x, const T& y) { return !(
4547
template <typename T> inline bool operator> (const T& x, const T& y) { return y < x; }
4648
template <typename T> inline bool operator<=(const T& x, const T& y) { return !(y < x); }
4749
template <typename T> inline bool operator>=(const T& x, const T& y) { return !(x < y); }
50+
}

uvector.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "umemory.h"
1010
//#include "upredalgo.h"
1111

12+
namespace ustl {
1213

1314
//TODO: the iterators do not become 'invalidated' ever
1415

@@ -25,8 +26,8 @@ class vector {
2526
typedef const value_type* const_pointer;
2627
typedef pointer iterator;
2728
typedef const_pointer const_iterator;
28-
typedef ::reverse_iterator<iterator> reverse_iterator;
29-
typedef ::reverse_iterator<const_iterator> const_reverse_iterator;
29+
typedef ustl::reverse_iterator<iterator> reverse_iterator;
30+
typedef ustl::reverse_iterator<const_iterator> const_reverse_iterator;
3031
protected:
3132
typedef vector<T>& my_ref;
3233
typedef const vector<T>& const_my_ref;
@@ -242,3 +243,5 @@ inline void vector<T>::swap(vector<T>& v) {
242243
}
243244

244245
// TODO: optimized version for vector<bool>
246+
247+
}

0 commit comments

Comments
 (0)
0