1 // Created on: 2004-03-05
2 // Created by: Mikhail KUZMITCHEV
3 // Copyright (c) 2004-2012 OPEN CASCADE SAS
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.
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.
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.
22 #include <QANCollection.hxx>
23 #include <Draw_Interpretor.hxx>
25 #include <NCollection_StdAllocator.hxx>
26 #include <NCollection_IncAllocator.hxx>
30 //=======================================================================
31 //function : QANColStdAllocator1
33 //=======================================================================
34 static Standard_Integer QANColStdAllocator1(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
37 di << "Usage : " << argv[0] << "\n";
42 typedef Handle_Standard_Transient elem_type;
43 typedef NCollection_StdAllocator<elem_type> allocator_type;
44 if ( sizeof (allocator_type::value_type) == sizeof (elem_type) ) {
45 di << "value_type : OK\n";
47 di << "value_type : Error\n";
49 if ( sizeof (allocator_type::pointer) == sizeof (void*) ) {
50 di << "pointer : OK\n";
52 di << "pointer : Error\n";
54 if (sizeof (allocator_type::const_pointer) == sizeof (void*) ) {
55 di << "const_pointer : OK\n";
57 di << "const_pointer : Error\n";
61 allocator_type::reference aRef = aDummy;
62 allocator_type::const_reference aConstRef = aDummy;
63 if ( sizeof (allocator_type::size_type) == sizeof (size_t) ) {
64 di << "size_type : OK\n";
66 di << "size_type : Error\n";
68 if ( sizeof (allocator_type::difference_type) == sizeof (ptrdiff_t) ) {
69 di << "allocator_type : OK\n";
71 di << "allocator_type : Error\n";
74 typedef int other_elem_type;
75 if ( sizeof (allocator_type::rebind<other_elem_type>::other::value_type) == sizeof (other_elem_type) ) {
76 di << "other_elem_type : OK\n";
78 di << "other_elem_type : Error\n";
84 //=======================================================================
85 //function : QANColStdAllocator2
87 //=======================================================================
88 static Standard_Integer QANColStdAllocator2(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
91 di << "Usage : " << argv[0] << "\n";
95 //create incremental allocator outside the scope of objects it will manage
96 Handle(NCollection_IncAllocator) anIncAlloc = new NCollection_IncAllocator();
100 NCollection_StdAllocator<int> aSAlloc (anIncAlloc);
101 std::list<int, NCollection_StdAllocator<int> > aL (aSAlloc);
103 if ( aL.size() == size_t (1) ) {
104 di << "Test1 : OK\n";
106 di << "Test1 : Error\n";
110 NCollection_StdAllocator<char> aCAlloc;
111 std::vector<int, NCollection_StdAllocator<int> > aV (aCAlloc);
113 if ( aV.size() == size_t (1) ) {
114 di << "Test2 : OK\n";
116 di << "Test2 : Error\n";
119 //using void-specialization allocator
120 NCollection_StdAllocator<void> aVAlloc;
121 std::vector<int, NCollection_StdAllocator<int> > aV2 (aVAlloc);
125 if ( aV2.size() == size_t (11) ) {
126 di << "Test3 : OK\n";
128 di << "Test3 : Error\n";
131 //equality of allocators
132 if ( aSAlloc != aCAlloc ) {
133 di << "Test4 : OK\n";
135 di << "Test4 : Error\n";
137 NCollection_StdAllocator<int> anIAlloc (anIncAlloc);
138 if ( aSAlloc == anIAlloc ) {
139 di << "Test5 : OK\n";
141 di << "Test5 : Error\n";
149 void QANCollection::Commands4(Draw_Interpretor& theCommands) {
150 const char *group = "QANCollection";
152 theCommands.Add("QANColStdAllocator1", "QANColStdAllocator1", __FILE__, QANColStdAllocator1, group);
153 theCommands.Add("QANColStdAllocator2", "QANColStdAllocator2", __FILE__, QANColStdAllocator2, group);