File: TestClass.h

package info (click to toggle)
stlport4.6 4.6.2-7
  • links: PTS, VCS
  • area: main
  • in suites: squeeze, wheezy
  • size: 7,056 kB
  • ctags: 16,390
  • sloc: ansic: 46,190; cpp: 18,805; sh: 266; asm: 93; perl: 58; makefile: 10
file content (172 lines) | stat: -rw-r--r-- 3,869 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/***********************************************************************************
	TestClass.h
	
 * Copyright (c) 1997-1998
 * Mark of the Unicorn, Inc.
 *
 * Permission to use, copy, modify, distribute and sell this software
 * and its documentation for any purpose is hereby granted without fee,
 * provided that the above copyright notice appear in all copies and
 * that both that copyright notice and this permission notice appear
 * in supporting documentation.  Mark of the Unicorn makes no
 * representations about the suitability of this software for any
 * purpose.  It is provided "as is" without express or implied warranty.
		
		SUMMARY: TestClass simulates a class that uses resources. It is designed to
			cause exceptions when it is constructed or copied.
		
***********************************************************************************/
#ifndef INCLUDED_MOTU_TestClass
#define INCLUDED_MOTU_TestClass 1

# include "Prefix.h"

# if defined (EH_NEW_HEADERS)
#  include <functional>
#  include <utility>
#  include <climits>
# else
#  include <function.h>
#  include <pair.h>
#  include <limits.h>
# endif


#include <iosfwd>
#include "random_number.h"
#include "nc_alloc.h"

class TestClass
{
public:
    inline TestClass();
    inline TestClass( int value );
    inline TestClass( const TestClass& rhs );
    inline ~TestClass();
    
    inline TestClass& operator=( const TestClass& rhs );
    inline int value() const;
	
    inline TestClass operator!() const;

    bool operator==( const TestClass& rhs ) const
    {
      return value() == rhs.value();
    }

    bool operator<( const TestClass& rhs ) const {
      return value() < rhs.value();
    }

protected:
    static inline unsigned int get_random(unsigned range = UINT_MAX);
private:
	inline void Init( int value );

#if TESTCLASS_DEEP_DATA
    int *p;
#else
	int v;
#endif
};

#if defined( __MWERKS__ ) && __MWERKS__ <= 0x3000 && !__SGI_STL
# if defined( __MSL__ ) && __MSL__ < 0x2406
#  include <iterator.h>
__MSL_FIX_ITERATORS__(TestClass);
__MSL_FIX_ITERATORS__(const TestClass);
typedef EH_STD::pair<const TestClass, TestClass> pair_testclass_testclass;
__MSL_FIX_ITERATORS__( pair_testclass_testclass );
__MSL_FIX_ITERATORS__( const pair_testclass_testclass );
# endif
#endif

inline void TestClass::Init( int value )
{
#if TESTCLASS_DEEP_DATA
	p = new int( value );
#else
	simulate_constructor();
	v = value;
#endif
}

inline TestClass::TestClass()
{
	Init( int(get_random()) );
}

inline TestClass::TestClass( int value )
{
	Init( value );
}

inline TestClass::TestClass( const TestClass& rhs )
{
	Init( rhs.value() );
}

inline TestClass::~TestClass()
{
#if TESTCLASS_DEEP_DATA
	delete p;
#else
	simulate_destructor();
#endif
}

inline TestClass& TestClass::operator=( const TestClass& rhs )
{
#if TESTCLASS_DEEP_DATA
	int *newP = new int( rhs.value() );
	delete p;
	p = newP;
#else
	simulate_possible_failure();
    v = rhs.value();
#endif
    return *this;
}

inline int TestClass::value() const
{
#if TESTCLASS_DEEP_DATA
	return *p;
#else
	return v;
#endif
}

inline TestClass TestClass::operator!() const
{
    return TestClass( value()+1 );
}

inline bool operator>( const TestClass& lhs, const TestClass& rhs ) {
    return rhs < lhs;
}

inline bool operator>=( const TestClass& lhs, const TestClass& rhs ) {
    return !(lhs < rhs);
}

inline bool operator<=( const TestClass& lhs, const TestClass& rhs ) {
    return !(rhs < lhs);
}

inline bool operator != ( const TestClass& lhs, const TestClass& rhs ) {
    return lhs.value() != rhs.value();
}

inline unsigned int TestClass::get_random( unsigned range )
{
    return random_number( range );
}

# ifdef EH_NEW_IOSTREAMS
extern EH_STD::ostream& operator << ( EH_STD::ostream& s, const TestClass&);
# else
extern ostream& operator << ( ostream& s, const TestClass&);
# endif

#endif // INCLUDED_MOTU_TestClass