1 // Created on: 2004-03-05
2 // Created by: Mikhail KUZMITCHEV
3 // Copyright (c) 2004-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <QANCollection.hxx>
17 #include <Draw_Interpretor.hxx>
19 #include <NCollection_StdAllocator.hxx>
20 #include <NCollection_IncAllocator.hxx>
21 #include <Standard_Assert.hxx>
26 //=======================================================================
27 //function : QANColStdAllocator1
29 //=======================================================================
30 static Standard_Integer QANColStdAllocator1(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
33 di << "Usage : " << argv[0] << "\n";
38 typedef Handle(Standard_Transient) elem_type;
39 typedef NCollection_StdAllocator<elem_type> allocator_type;
40 Standard_STATIC_ASSERT (sizeof (allocator_type::value_type) == sizeof (elem_type));
41 Standard_STATIC_ASSERT (sizeof (allocator_type::pointer) == sizeof (void*));
42 Standard_STATIC_ASSERT (sizeof (allocator_type::const_pointer) == sizeof (void*));
45 allocator_type::reference aRef = aDummy;
46 (void)aRef; // avoid compiler warning on unused
47 allocator_type::const_reference aConstRef = aDummy;
48 (void)aConstRef; // avoid compiler warning on unused
49 Standard_STATIC_ASSERT (sizeof (allocator_type::size_type) == sizeof (size_t));
50 Standard_STATIC_ASSERT (sizeof (allocator_type::difference_type) == sizeof (ptrdiff_t));
52 typedef int other_elem_type;
53 Standard_STATIC_ASSERT (sizeof (allocator_type::rebind<other_elem_type>::other::value_type) == sizeof (other_elem_type));
58 //=======================================================================
59 //function : QANColStdAllocator2
61 //=======================================================================
62 static Standard_Integer QANColStdAllocator2(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
65 di << "Usage : " << argv[0] << "\n";
69 //create incremental allocator outside the scope of objects it will manage
70 Handle(NCollection_IncAllocator) anIncAlloc = new NCollection_IncAllocator();
74 NCollection_StdAllocator<int> aSAlloc (anIncAlloc);
75 std::list<int, NCollection_StdAllocator<int> > aL (aSAlloc);
77 if ( aL.size() == size_t (1) ) {
80 di << "Test1 : Error\n";
84 NCollection_StdAllocator<char> aCAlloc;
85 std::vector<int, NCollection_StdAllocator<int> > aV (aCAlloc);
87 if ( aV.size() == size_t (1) ) {
90 di << "Test2 : Error\n";
93 //using void-specialization allocator
94 NCollection_StdAllocator<void> aVAlloc;
95 std::vector<int, NCollection_StdAllocator<int> > aV2 (aVAlloc);
99 if ( aV2.size() == size_t (11) ) {
100 di << "Test3 : OK\n";
102 di << "Test3 : Error\n";
105 //equality of allocators
106 if ( aSAlloc != aCAlloc ) {
107 di << "Test4 : OK\n";
109 di << "Test4 : Error\n";
111 NCollection_StdAllocator<int> anIAlloc (anIncAlloc);
112 if ( aSAlloc == anIAlloc ) {
113 di << "Test5 : OK\n";
115 di << "Test5 : Error\n";
123 void QANCollection::CommandsAlloc(Draw_Interpretor& theCommands) {
124 const char *group = "QANCollection";
126 theCommands.Add("QANColStdAllocator1", "QANColStdAllocator1", __FILE__, QANColStdAllocator1, group);
127 theCommands.Add("QANColStdAllocator2", "QANColStdAllocator2", __FILE__, QANColStdAllocator2, group);