ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libptytty/src/estl.h
(Generate patch)

Comparing libptytty/src/estl.h (file contents):
Revision 1.27 by sf-exg, Fri Nov 7 20:44:49 2014 UTC vs.
Revision 1.28 by sf-exg, Mon Nov 10 11:32:00 2014 UTC

23#include <new> 23#include <new>
24 24
25#if ECB_CPP11 25#if ECB_CPP11
26 #include <type_traits> 26 #include <type_traits>
27#endif 27#endif
28
29namespace estl
30{
31#if ESTL_LARGE_MEMORY_MODEL
32 // should use size_t/ssize_t, but that's not portable enough for us
33 typedef unsigned long size_type;
34 typedef long difference_type;
35#else
36 typedef uint32_t size_type;
37 typedef int32_t difference_type;
38#endif
39
40 template<typename T>
41 struct scoped_ptr
42 {
43 T *p;
44
45 scoped_ptr () : p (0) { }
46
47 explicit
48 scoped_ptr (T *a) : p (a) { }
49
50 ~scoped_ptr ()
51 {
52 delete p;
53 }
54
55 void reset (T *a)
56 {
57 delete p;
58 p = a;
59 }
60
61 T *operator ->() const { return p; }
62 T &operator *() const { return *p; }
63
64 operator T *() { return p; }
65 T *get () const { return p; }
66 };
67
68 template<typename T>
69 struct scoped_array
70 {
71 T *p;
72
73 scoped_array () : p (0) { }
74
75 explicit
76 scoped_array (T *a) : p (a) { }
77
78 ~scoped_array ()
79 {
80 delete [] p;
81 }
82
83 void reset (T *a)
84 {
85 delete [] p;
86 p = a;
87 }
88
89 T & operator [](size_type idx) const { return p[idx]; }
90
91 operator T *() { return p; }
92 T *get () const { return p; }
93 };
94}
28 95
29// original version taken from MICO, but this has been completely rewritten 96// original version taken from MICO, but this has been completely rewritten
30// known limitations w.r.t. std::vector 97// known limitations w.r.t. std::vector
31// - many methods missing 98// - many methods missing
32// - no error checking, no exceptions thrown (e.g. at()) 99// - no error checking, no exceptions thrown (e.g. at())
36// - we don't care about namespaces and stupid macros the user might define 103// - we don't care about namespaces and stupid macros the user might define
37// - no bool specialisation 104// - no bool specialisation
38template<class T> 105template<class T>
39struct simplevec 106struct simplevec
40{ 107{
41#if ESTL_BIG_VECTOR 108 typedef estl::size_type size_type;
42 // should use size_t/ssize_t, but that's not portable enough for us
43 typedef unsigned long size_type;
44 typedef long difference_type;
45#else
46 typedef uint32_t size_type;
47 typedef int32_t difference_type;
48#endif
49 109
50 typedef T value_type; 110 typedef T value_type;
51 typedef T *iterator; 111 typedef T *iterator;
52 typedef const T *const_iterator; 112 typedef const T *const_iterator;
53 typedef T *pointer; 113 typedef T *pointer;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines