diff options
Diffstat (limited to '')
-rw-r--r-- | src/buffer.cpp | 1 | ||||
-rw-r--r-- | src/fastcgi.cpp | 14 | ||||
-rw-r--r-- | src/fstring.cpp | 6 | ||||
-rw-r--r-- | src/httpget.cpp | 5 | ||||
-rw-r--r-- | src/sharedcore.cpp | 9 | ||||
-rw-r--r-- | src/sharedcore.h | 101 | ||||
-rw-r--r-- | src/tests/sharedcore.cpp | 82 | ||||
-rw-r--r-- | src/unit/list.unit | 68 | ||||
-rw-r--r-- | src/util.h | 4 |
9 files changed, 275 insertions, 15 deletions
diff --git a/src/buffer.cpp b/src/buffer.cpp index d4eb8a6..c5a972a 100644 --- a/src/buffer.cpp +++ b/src/buffer.cpp | |||
@@ -34,6 +34,7 @@ void Bu::Buffer::start() | |||
34 | 34 | ||
35 | size_t Bu::Buffer::stop() | 35 | size_t Bu::Buffer::stop() |
36 | { | 36 | { |
37 | return 0; | ||
37 | } | 38 | } |
38 | 39 | ||
39 | void Bu::Buffer::fillReadBuf() | 40 | void Bu::Buffer::fillReadBuf() |
diff --git a/src/fastcgi.cpp b/src/fastcgi.cpp index 9aecbfb..3cc3a10 100644 --- a/src/fastcgi.cpp +++ b/src/fastcgi.cpp | |||
@@ -278,7 +278,9 @@ void Bu::FastCgi::run() | |||
278 | // sio << "Scary."; | 278 | // sio << "Scary."; |
279 | // ??? we shouldn't get these. | 279 | // ??? we shouldn't get these. |
280 | break; | 280 | break; |
281 | 281 | ||
282 | case typeGetValues: | ||
283 | break; | ||
282 | } | 284 | } |
283 | 285 | ||
284 | // sio << sio.nl; | 286 | // sio << sio.nl; |
@@ -313,10 +315,7 @@ void Bu::FastCgi::run() | |||
313 | iSize = 65528; | 315 | iSize = 65528; |
314 | rOut.uContentLength = iSize; | 316 | rOut.uContentLength = iSize; |
315 | write( s, rOut ); | 317 | write( s, rOut ); |
316 | int iAmnt = s.write( | 318 | s.write( sStdOut.getStr()+iPos, iSize ); |
317 | sStdOut.getStr()+iPos, iSize ); | ||
318 | // sio << "Wrote " << iAmnt << | ||
319 | // " of " << iSize << sio.nl; | ||
320 | } | 319 | } |
321 | } | 320 | } |
322 | rOut.uContentLength = 0; | 321 | rOut.uContentLength = 0; |
@@ -333,10 +332,7 @@ void Bu::FastCgi::run() | |||
333 | iSize = 65528; | 332 | iSize = 65528; |
334 | rOut.uContentLength = iSize; | 333 | rOut.uContentLength = iSize; |
335 | write( s, rOut ); | 334 | write( s, rOut ); |
336 | int iAmnt = s.write( | 335 | s.write( sStdErr.getStr()+iPos, iSize ); |
337 | sStdErr.getStr()+iPos, iSize ); | ||
338 | // sio << "Wrote " << iAmnt << | ||
339 | // " of " << iSize << sio.nl; | ||
340 | } | 336 | } |
341 | } | 337 | } |
342 | rOut.uContentLength = 0; | 338 | rOut.uContentLength = 0; |
diff --git a/src/fstring.cpp b/src/fstring.cpp index ce5492b..f77e718 100644 --- a/src/fstring.cpp +++ b/src/fstring.cpp | |||
@@ -110,15 +110,13 @@ int64_t &Bu::operator<<( int64_t &dst, const Bu::FString &sIn ) | |||
110 | 110 | ||
111 | float &Bu::operator<<( float &dst, const Bu::FString &sIn ) | 111 | float &Bu::operator<<( float &dst, const Bu::FString &sIn ) |
112 | { | 112 | { |
113 | double tmp; | 113 | sscanf( sIn.getStr(), "%f", &dst ); |
114 | sscanf( sIn.getStr(), "%f", &tmp ); | ||
115 | dst = tmp; | ||
116 | return dst; | 114 | return dst; |
117 | } | 115 | } |
118 | 116 | ||
119 | double &Bu::operator<<( double &dst, const Bu::FString &sIn ) | 117 | double &Bu::operator<<( double &dst, const Bu::FString &sIn ) |
120 | { | 118 | { |
121 | sscanf( sIn.getStr(), "%f", &dst ); | 119 | sscanf( sIn.getStr(), "%lf", &dst ); |
122 | return dst; | 120 | return dst; |
123 | } | 121 | } |
124 | 122 | ||
diff --git a/src/httpget.cpp b/src/httpget.cpp index 0356874..369f27b 100644 --- a/src/httpget.cpp +++ b/src/httpget.cpp | |||
@@ -34,11 +34,12 @@ void Bu::HttpGet::get() | |||
34 | // sSrv.read( | 34 | // sSrv.read( |
35 | } | 35 | } |
36 | 36 | ||
37 | size_t Bu::HttpGet::read( void *pBuf, size_t nBytes ) | 37 | size_t Bu::HttpGet::read( void * /*pBuf*/, size_t /*nBytes*/ ) |
38 | { | 38 | { |
39 | return 0; | ||
39 | } | 40 | } |
40 | 41 | ||
41 | size_t Bu::HttpGet::write( const void *pBuf, size_t nBytes ) | 42 | size_t Bu::HttpGet::write( const void * /*pBuf*/, size_t /*nBytes*/ ) |
42 | { | 43 | { |
43 | return 0; | 44 | return 0; |
44 | } | 45 | } |
diff --git a/src/sharedcore.cpp b/src/sharedcore.cpp new file mode 100644 index 0000000..6333335 --- /dev/null +++ b/src/sharedcore.cpp | |||
@@ -0,0 +1,9 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2008 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/sharedcore.h" | ||
9 | |||
diff --git a/src/sharedcore.h b/src/sharedcore.h new file mode 100644 index 0000000..9f42345 --- /dev/null +++ b/src/sharedcore.h | |||
@@ -0,0 +1,101 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2008 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #ifndef BU_SHARED_CORE_H | ||
9 | #define BU_SHARED_CORE_H | ||
10 | |||
11 | #include "bu/util.h" | ||
12 | #include "bu/sio.h" | ||
13 | |||
14 | namespace Bu | ||
15 | { | ||
16 | template<typename Core> | ||
17 | class SharedCore | ||
18 | { | ||
19 | typedef class SharedCore<Core> _SharedType; | ||
20 | public: | ||
21 | SharedCore() : | ||
22 | data( new Core ), | ||
23 | iRefCount( new int(1) ) | ||
24 | { | ||
25 | } | ||
26 | |||
27 | SharedCore( const _SharedType &rSrc ) : | ||
28 | data( NULL ), | ||
29 | iRefCount( NULL ) | ||
30 | { | ||
31 | _softCopy( rSrc ); | ||
32 | } | ||
33 | |||
34 | virtual ~SharedCore() | ||
35 | { | ||
36 | _deref(); | ||
37 | } | ||
38 | |||
39 | SharedCore &operator=( const SharedCore &rhs ) | ||
40 | { | ||
41 | _softCopy( rhs ); | ||
42 | return *this; | ||
43 | } | ||
44 | |||
45 | int getRefCount() const | ||
46 | { | ||
47 | return *iRefCount; | ||
48 | } | ||
49 | |||
50 | protected: | ||
51 | Core *data; | ||
52 | void _hardCopy() | ||
53 | { | ||
54 | if( !data || !iRefCount ) | ||
55 | return; | ||
56 | sio << "_hardCopy()" << sio.nl; | ||
57 | Core *copy = new Core( *data ); | ||
58 | _deref(); | ||
59 | data = copy; | ||
60 | iRefCount = new int( 1 ); | ||
61 | } | ||
62 | |||
63 | private: | ||
64 | void _deref() | ||
65 | { | ||
66 | sio << "_deref()" << sio.nl; | ||
67 | if( (--(*iRefCount)) == 0 ) | ||
68 | { | ||
69 | sio << " --> iRefCount == 0, cleaning up." << sio.nl; | ||
70 | delete data; | ||
71 | delete iRefCount; | ||
72 | } | ||
73 | else | ||
74 | sio << " --> iRefCount == " << *iRefCount << sio.nl; | ||
75 | data = NULL; | ||
76 | iRefCount = NULL; | ||
77 | } | ||
78 | |||
79 | void _incRefCount() | ||
80 | { | ||
81 | sio << "_incRefCount()" << sio.nl; | ||
82 | if( iRefCount && data ) | ||
83 | ++(*iRefCount); | ||
84 | sio << " --> iRefCount == " << *iRefCount << sio.nl; | ||
85 | } | ||
86 | |||
87 | void _softCopy( const _SharedType &rSrc ) | ||
88 | { | ||
89 | sio << "_softCopy()" << sio.nl; | ||
90 | if( data ) | ||
91 | _deref(); | ||
92 | data = rSrc.data; | ||
93 | iRefCount = rSrc.iRefCount; | ||
94 | _incRefCount(); | ||
95 | } | ||
96 | |||
97 | int *iRefCount; | ||
98 | }; | ||
99 | }; | ||
100 | |||
101 | #endif | ||
diff --git a/src/tests/sharedcore.cpp b/src/tests/sharedcore.cpp new file mode 100644 index 0000000..bdfde4c --- /dev/null +++ b/src/tests/sharedcore.cpp | |||
@@ -0,0 +1,82 @@ | |||
1 | #include "bu/sharedcore.h" | ||
2 | #include "bu/sio.h" | ||
3 | |||
4 | using namespace Bu; | ||
5 | |||
6 | struct ShintCore | ||
7 | { | ||
8 | int val; | ||
9 | }; | ||
10 | class Shint : public Bu::SharedCore<struct ShintCore> | ||
11 | { | ||
12 | public: | ||
13 | Shint() | ||
14 | { | ||
15 | data->val = 0; | ||
16 | } | ||
17 | |||
18 | Shint( int val ) | ||
19 | { | ||
20 | data->val = val; | ||
21 | } | ||
22 | |||
23 | int getVal() | ||
24 | { | ||
25 | return data->val; | ||
26 | } | ||
27 | |||
28 | void setValBad( int val ) | ||
29 | { | ||
30 | data->val = val; | ||
31 | } | ||
32 | |||
33 | void setVal( int val ) | ||
34 | { | ||
35 | _hardCopy(); | ||
36 | data->val = val; | ||
37 | } | ||
38 | |||
39 | bool operator==( const Shint &rhs ) | ||
40 | { | ||
41 | if( data == rhs.data ) | ||
42 | { | ||
43 | sio << "Same pointer (" << Fmt::ptr() << data << ")" << sio.nl; | ||
44 | return true; | ||
45 | } | ||
46 | if( data->val == rhs.data->val ) | ||
47 | { | ||
48 | sio << "Same value " << data->val << " (" | ||
49 | << Fmt::ptr() << data << " vs " | ||
50 | << Fmt::ptr() << rhs.data << ")" | ||
51 | << sio.nl; | ||
52 | return true; | ||
53 | } | ||
54 | sio << "Different" << sio.nl; | ||
55 | return false; | ||
56 | } | ||
57 | }; | ||
58 | |||
59 | #define line( x ) sio << __FILE__ ": " << __LINE__ << ": " << #x << sio.nl; x | ||
60 | |||
61 | int main() | ||
62 | { | ||
63 | line( Shint a; ) | ||
64 | line( Shint b( 5 ); ) | ||
65 | |||
66 | line( a == b; ) | ||
67 | |||
68 | line( b = a; ) | ||
69 | line( a == b; ) | ||
70 | |||
71 | line( b.setValBad( 12 ); ) | ||
72 | sio << a.getVal() << " != " << b.getVal() << sio.nl; | ||
73 | line( a == b; ) | ||
74 | |||
75 | line( a.setVal( 3 ); ) | ||
76 | sio << a.getVal() << " != " << b.getVal() << sio.nl; | ||
77 | line( a == b; ) | ||
78 | |||
79 | line( a.setVal( b.getVal() ); ) | ||
80 | line( a == b; ) | ||
81 | } | ||
82 | |||
diff --git a/src/unit/list.unit b/src/unit/list.unit new file mode 100644 index 0000000..9da0342 --- /dev/null +++ b/src/unit/list.unit | |||
@@ -0,0 +1,68 @@ | |||
1 | // vim: syntax=cpp | ||
2 | /* | ||
3 | * Copyright (C) 2007-2008 Xagasoft, All rights reserved. | ||
4 | * | ||
5 | * This file is part of the libbu++ library and is released under the | ||
6 | * terms of the license contained in the file LICENSE. | ||
7 | */ | ||
8 | |||
9 | #include "bu/fstring.h" | ||
10 | #include "bu/list.h" | ||
11 | |||
12 | typedef Bu::List<int> IntList; | ||
13 | |||
14 | {=Init} | ||
15 | |||
16 | {%append} | ||
17 | { | ||
18 | IntList lst; | ||
19 | for( int j = 0; j < 50; j++ ) | ||
20 | { | ||
21 | lst.append( j ); | ||
22 | } | ||
23 | int j = 0; | ||
24 | for( IntList::iterator i = lst.begin(); i; i++, j++ ) | ||
25 | { | ||
26 | unitTest( *i == j ); | ||
27 | } | ||
28 | } | ||
29 | |||
30 | {%prepend} | ||
31 | { | ||
32 | IntList lst; | ||
33 | for( int j = 0; j < 50; j++ ) | ||
34 | { | ||
35 | lst.prepend( j ); | ||
36 | } | ||
37 | int j = 49; | ||
38 | for( IntList::iterator i = lst.begin(); i; i++, j-- ) | ||
39 | { | ||
40 | unitTest( *i == j ); | ||
41 | } | ||
42 | } | ||
43 | |||
44 | {%copy} | ||
45 | { | ||
46 | IntList lst; | ||
47 | int j; | ||
48 | for( j = 0; j < 50; j++ ) | ||
49 | { | ||
50 | lst.append( j ); | ||
51 | } | ||
52 | IntList lst2 = lst; | ||
53 | |||
54 | j = 0; | ||
55 | for( IntList::iterator i = lst2.begin(); i; i++, j++ ) | ||
56 | { | ||
57 | unitTest( *i == j ); | ||
58 | } | ||
59 | lst2.clear(); | ||
60 | lst2 = lst; | ||
61 | |||
62 | j = 0; | ||
63 | for( IntList::iterator i = lst2.begin(); i; i++, j++ ) | ||
64 | { | ||
65 | unitTest( *i == j ); | ||
66 | } | ||
67 | } | ||
68 | |||
@@ -8,6 +8,10 @@ | |||
8 | #ifndef BU_UTIL_H | 8 | #ifndef BU_UTIL_H |
9 | #define BU_UTIL_H | 9 | #define BU_UTIL_H |
10 | 10 | ||
11 | #ifndef NULL | ||
12 | #define NULL 0 | ||
13 | #endif | ||
14 | |||
11 | /* I borrowed this from someone who borrowed it from glib who borrowed it | 15 | /* I borrowed this from someone who borrowed it from glib who borrowed it |
12 | * from... | 16 | * from... |
13 | */ | 17 | */ |