soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
sstringdata.cpp
1
2#include "string/sstringdata.h"
3#include "soui_mem_wrapper.h"
4#include <windows.h>
5
6SNSBEGIN
7 // Globals
8
9 // For an empty string, m_pszData will point here
10 // (note: avoids special case of checking for NULL m_pszData)
11 // empty string data (and locked)
12 static int _tstr_rgInitData[] = { -1, 0, 0, 0, 0, 0, 0, 0 };
13
14 TStringData* TStringData::InitDataNil()
15 {
16 static TStringData* _tstr_initDataNil = (TStringData*)&_tstr_rgInitData;
17 return _tstr_initDataNil;
18 }
19
20 const void* TStringData::InitPszNil()
21 {
22 static const void* _tstr_initPszNil = (const void*)(((unsigned char*)&_tstr_rgInitData) + sizeof(TStringData));
23 return _tstr_initPszNil;
24 }
25
26 void* TStringData::data() const
27 {
28 return (void*)(this + 1);
29 }
30
31 void TStringData::Unlock()
32 {
33 SASSERT(IsLocked());
34 if (IsLocked())
35 {
36 nRefs++; // Locked buffers can't be shared, so no interlocked operation necessary
37 if (nRefs == 0)
38 nRefs = 1;
39 }
40 }
41
42 void TStringData::Lock()
43 {
44 SASSERT(nRefs <= 1);
45 nRefs--; // Locked buffers can't be shared, so no interlocked operation necessary
46 if (nRefs == 0)
47 nRefs = -1;
48 }
49
50 bool TStringData::IsLocked() const
51 {
52 return nRefs < 0;
53 }
54
55 bool TStringData::IsShared() const
56 {
57 return nRefs > 1;
58 }
59
60 void TStringData::Release()
61 {
62 SASSERT(nRefs != 0);
63 if (--nRefs <= 0)
64 soui_mem_wrapper::SouiFree(this);
65 }
66
67 void TStringData::AddRef()
68 {
69 SASSERT(nRefs > 0);
70 nRefs++;
71 }
72
73SNSEND