Skip to content
This repository was archived by the owner on Aug 19, 2024. It is now read-only.

Commit 1aba1f8

Browse files
committed
Add & Change WIP MSVC binary compatibility structures
1 parent 974e975 commit 1aba1f8

6 files changed

Lines changed: 116 additions & 17 deletions

File tree

cwsdk/msvc_bincompat/map.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include "map.h"
2+
3+
// Binary compatability for MS VC++ 11.0 / _MSC_VER=1700
4+
namespace MSVCBinCompat {
5+
};

cwsdk/msvc_bincompat/map.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#pragma once
2+
#include <cstdint>
3+
#include <map>
4+
5+
// Binary compatability for MS VC++ 11.0 / _MSC_VER=1700
6+
namespace MSVCBinCompat {
7+
// MSVC red-black binary search tree node
8+
struct RBBST_node
9+
{
10+
RBBST_node *left;
11+
RBBST_node *parent;
12+
RBBST_node *right;
13+
char color;
14+
char isnil;
15+
__int16 _pad;
16+
};
17+
18+
template <typename KT, typename VT>
19+
struct MyMap_node
20+
{
21+
RBBST_node rbbst;
22+
KT key;
23+
VT val;
24+
};
25+
26+
template <typename KT, typename VT>
27+
struct map {
28+
typedef MyMap_node<KT, VT> node_t;
29+
private:
30+
node_t head;
31+
void inorder(node_t* node, std::map<KT, VT>* output)
32+
{
33+
if (!node->rbbst.isnil) {
34+
inorder((node_t*)node->rbbst.left, output);
35+
output->insert_or_assign(node->key, node->val);
36+
inorder((node_t*)node->rbbst.right, output);
37+
}
38+
}
39+
public:
40+
std::map<KT, VT> CopyToSTDMap() {
41+
auto out = std::map<KT, VT>();
42+
inorder((node_t*)head.rbbst.parent, &out);
43+
return out;
44+
}
45+
// Search
46+
// Insert
47+
// Delete
48+
};
49+
};

cwsdk/msvc_bincompat/string.cpp

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "string.h"
22

33
// Binary compatability for MS VC++ 11.0 / _MSC_VER=1700
4-
namespace MSVCBinCompat{
4+
namespace MSVCBinCompat {
55
string::~string()
66
{
77
// Free memory if cap is greater than sbo size.
@@ -17,7 +17,7 @@ namespace MSVCBinCompat{
1717
cap = 15;
1818
}
1919

20-
string::string(const char* c) : string()
20+
void string::set(const char* c)
2121
{
2222
if (c != nullptr)
2323
{
@@ -39,15 +39,18 @@ namespace MSVCBinCompat{
3939
cap = len;
4040
}
4141
}
42-
else
43-
{
44-
string();
45-
}
42+
}
43+
44+
string::string(const char* c) : string()
45+
{
46+
set(c);
4647
}
4748

4849
string::string(std::string s) : string(s.c_str()) {}
4950

50-
const char* string::c_str()
51+
string::string(const string& s) : string(s.c_str()) {}
52+
53+
const char* string::c_str() const
5154
{
5255
if (cap > 15)
5356
{
@@ -68,4 +71,17 @@ namespace MSVCBinCompat{
6871
return this->std();
6972
}
7073

74+
void string::changed() {
75+
auto data_ptr = this->c_str();
76+
auto len = strlen(data_ptr);
77+
char* data = new char[len + 1];
78+
memcpy(data, data_ptr, len + 1);
79+
set(data);
80+
delete[] data;
81+
}
7182
};
83+
84+
std::ostream& operator<< (std::ostream& os, MSVCBinCompat::string& str) {
85+
os << str.c_str();
86+
return os;
87+
}

cwsdk/msvc_bincompat/string.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,15 @@ namespace MSVCBinCompat{
1717
public:
1818
~string();
1919
string();
20+
void set(const char* c);
2021
string(const char* c);
2122
string(std::string s);
22-
const char* c_str();
23+
string(const string& s);
24+
const char* c_str() const;
2325
std::string std();
2426
operator std::string();
27+
void changed();
2528
};
2629
};
30+
31+
std::ostream& operator<< (std::ostream& os, MSVCBinCompat::string& dt);

cwsdk/msvc_bincompat/wstring.cpp

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "wstring.h"
22

3+
#include <string>
4+
35
// Binary compatability for MS VC++ 11.0 / _MSC_VER=1700
46
namespace MSVCBinCompat{
57
wstring::~wstring()
@@ -16,8 +18,8 @@ namespace MSVCBinCompat{
1618
size = 0;
1719
cap = 7;
1820
}
19-
20-
wstring::wstring(const wchar_t* c) : wstring()
21+
22+
void wstring::set(const wchar_t* c)
2123
{
2224
if (c != nullptr)
2325
{
@@ -39,15 +41,18 @@ namespace MSVCBinCompat{
3941
cap = len;
4042
}
4143
}
42-
else
43-
{
44-
wstring();
45-
}
44+
}
45+
46+
wstring::wstring(const wchar_t* c) : wstring()
47+
{
48+
set(c);
4649
}
4750

4851
wstring::wstring(std::wstring s) : wstring(s.c_str()) {}
4952

50-
const wchar_t* wstring::c_str()
53+
wstring::wstring(const wstring& s) : wstring(s.c_str()) {}
54+
55+
const wchar_t* wstring::c_str() const
5156
{
5257
if (cap > 7)
5358
{
@@ -67,4 +72,18 @@ namespace MSVCBinCompat{
6772
wstring::operator std::wstring() {
6873
return this->std();
6974
}
70-
};
75+
76+
void wstring::changed() {
77+
auto data_ptr = this->c_str();
78+
auto len = wcslen(data_ptr);
79+
wchar_t* data = new wchar_t[len + 1];
80+
memcpy(data, data_ptr, (len + 1) * 2);
81+
set(data);
82+
delete[] data;
83+
}
84+
};
85+
86+
std::wostream& operator<< (std::wostream& os, MSVCBinCompat::wstring& str) {
87+
os << str.std();
88+
return os;
89+
}

cwsdk/msvc_bincompat/wstring.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#pragma once
2+
#include <iostream>
23
#include <cstdint>
34
#include <string>
45

@@ -17,11 +18,15 @@ namespace MSVCBinCompat {
1718
public:
1819
~wstring();
1920
wstring();
21+
void set(const wchar_t* c);
2022
wstring(const wchar_t* c);
2123
wstring(std::wstring s);
22-
const wchar_t* c_str();
24+
wstring(const wstring& s);
25+
const wchar_t* c_str() const;
2326
std::wstring std();
2427
operator std::wstring();
28+
void changed();
2529
};
2630
}
2731

32+
std::wostream& operator<< (std::wostream& os, MSVCBinCompat::wstring& dt);

0 commit comments

Comments
 (0)