Commit | Line | Data |
---|---|---|
ed9161a4 RL |
1 | // Created on: 2004-03-05 |
2 | // Created by: Mikhail KUZMITCHEV | |
3 | // Copyright (c) 2004-2012 OPEN CASCADE SAS | |
4 | // | |
5 | // The content of this file is subject to the Open CASCADE Technology Public | |
6 | // License Version 6.5 (the "License"). You may not use the content of this file | |
7 | // except in compliance with the License. Please obtain a copy of the License | |
8 | // at http://www.opencascade.org and read it completely before using this file. | |
9 | // | |
10 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its | |
11 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. | |
12 | // | |
13 | // The Original Code and all software distributed under the License is | |
14 | // distributed on an "AS IS" basis, without warranty of any kind, and the | |
15 | // Initial Developer hereby disclaims all such warranties, including without | |
16 | // limitation, any warranties of merchantability, fitness for a particular | |
17 | // purpose or non-infringement. Please see the License for the specific terms | |
18 | // and conditions governing the rights and limitations under the License. | |
19 | ||
20 | ||
21 | ||
22 | #include <QANCollection.hxx> | |
23 | #include <Draw_Interpretor.hxx> | |
24 | ||
25 | #include <NCollection_StdAllocator.hxx> | |
26 | #include <NCollection_IncAllocator.hxx> | |
8b381bc3 | 27 | #include <Standard_Assert.hxx> |
28 | ||
ed9161a4 RL |
29 | #include <list> |
30 | #include <vector> | |
31 | ||
32 | //======================================================================= | |
33 | //function : QANColStdAllocator1 | |
16347bb8 | 34 | //purpose : |
ed9161a4 RL |
35 | //======================================================================= |
36 | static Standard_Integer QANColStdAllocator1(Draw_Interpretor& di, Standard_Integer argc, const char ** argv) | |
37 | { | |
38 | if ( argc != 1) { | |
39 | di << "Usage : " << argv[0] << "\n"; | |
40 | return 1; | |
41 | } | |
42 | ||
43 | //type definitions | |
44 | typedef Handle_Standard_Transient elem_type; | |
45 | typedef NCollection_StdAllocator<elem_type> allocator_type; | |
8b381bc3 | 46 | Standard_STATIC_ASSERT (sizeof (allocator_type::value_type) == sizeof (elem_type)); |
47 | Standard_STATIC_ASSERT (sizeof (allocator_type::pointer) == sizeof (void*)); | |
48 | Standard_STATIC_ASSERT (sizeof (allocator_type::const_pointer) == sizeof (void*)); | |
ed9161a4 RL |
49 | |
50 | elem_type aDummy; | |
51 | allocator_type::reference aRef = aDummy; | |
105aae76 | 52 | (void)aRef; // avoid compiler warning on unused |
ed9161a4 | 53 | allocator_type::const_reference aConstRef = aDummy; |
105aae76 | 54 | (void)aConstRef; // avoid compiler warning on unused |
8b381bc3 | 55 | Standard_STATIC_ASSERT (sizeof (allocator_type::size_type) == sizeof (size_t)); |
56 | Standard_STATIC_ASSERT (sizeof (allocator_type::difference_type) == sizeof (ptrdiff_t)); | |
ed9161a4 RL |
57 | |
58 | typedef int other_elem_type; | |
8b381bc3 | 59 | Standard_STATIC_ASSERT (sizeof (allocator_type::rebind<other_elem_type>::other::value_type) == sizeof (other_elem_type)); |
ed9161a4 RL |
60 | |
61 | return 0; | |
62 | } | |
63 | ||
64 | //======================================================================= | |
65 | //function : QANColStdAllocator2 | |
16347bb8 | 66 | //purpose : |
ed9161a4 RL |
67 | //======================================================================= |
68 | static Standard_Integer QANColStdAllocator2(Draw_Interpretor& di, Standard_Integer argc, const char ** argv) | |
69 | { | |
70 | if ( argc != 1) { | |
71 | di << "Usage : " << argv[0] << "\n"; | |
72 | return 1; | |
73 | } | |
74 | ||
75 | //create incremental allocator outside the scope of objects it will manage | |
76 | Handle(NCollection_IncAllocator) anIncAlloc = new NCollection_IncAllocator(); | |
77 | ||
78 | { | |
79 | //typed allocator | |
80 | NCollection_StdAllocator<int> aSAlloc (anIncAlloc); | |
81 | std::list<int, NCollection_StdAllocator<int> > aL (aSAlloc); | |
82 | aL.push_back (2); | |
83 | if ( aL.size() == size_t (1) ) { | |
84 | di << "Test1 : OK\n"; | |
85 | } else { | |
86 | di << "Test1 : Error\n"; | |
87 | } | |
88 | ||
89 | //type cast | |
90 | NCollection_StdAllocator<char> aCAlloc; | |
91 | std::vector<int, NCollection_StdAllocator<int> > aV (aCAlloc); | |
92 | aV.push_back (1); | |
93 | if ( aV.size() == size_t (1) ) { | |
94 | di << "Test2 : OK\n"; | |
95 | } else { | |
96 | di << "Test2 : Error\n"; | |
97 | } | |
98 | ||
99 | //using void-specialization allocator | |
16347bb8 | 100 | NCollection_StdAllocator<void> aVAlloc; |
101 | std::vector<int, NCollection_StdAllocator<int> > aV2 (aVAlloc); | |
102 | ||
ed9161a4 RL |
103 | aV2.resize (10); |
104 | aV2.push_back (-1); | |
105 | if ( aV2.size() == size_t (11) ) { | |
106 | di << "Test3 : OK\n"; | |
107 | } else { | |
108 | di << "Test3 : Error\n"; | |
109 | } | |
110 | ||
111 | //equality of allocators | |
112 | if ( aSAlloc != aCAlloc ) { | |
113 | di << "Test4 : OK\n"; | |
114 | } else { | |
115 | di << "Test4 : Error\n"; | |
116 | } | |
117 | NCollection_StdAllocator<int> anIAlloc (anIncAlloc); | |
118 | if ( aSAlloc == anIAlloc ) { | |
119 | di << "Test5 : OK\n"; | |
120 | } else { | |
121 | di << "Test5 : Error\n"; | |
122 | } | |
123 | ||
124 | } | |
125 | ||
126 | return 0; | |
127 | } | |
128 | ||
129 | void QANCollection::Commands4(Draw_Interpretor& theCommands) { | |
130 | const char *group = "QANCollection"; | |
131 | ||
16347bb8 | 132 | theCommands.Add("QANColStdAllocator1", "QANColStdAllocator1", __FILE__, QANColStdAllocator1, group); |
133 | theCommands.Add("QANColStdAllocator2", "QANColStdAllocator2", __FILE__, QANColStdAllocator2, group); | |
ed9161a4 RL |
134 | |
135 | return; | |
136 | } |