1757
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
1757
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
1757
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (octave_str_vec_h) |
|
25 #define octave_str_vec_h 1 |
|
26 |
3503
|
27 #include <iostream> |
5880
|
28 #include <list> |
1757
|
29 #include <string> |
|
30 |
|
31 #include "Array.h" |
|
32 |
|
33 class |
3504
|
34 string_vector : public Array<std::string> |
1757
|
35 { |
|
36 public: |
1879
|
37 |
3504
|
38 string_vector (void) : Array<std::string> () { } |
1879
|
39 |
5275
|
40 explicit string_vector (octave_idx_type n) : Array<std::string> (n) { } |
1879
|
41 |
3504
|
42 string_vector (const char *s) : Array<std::string> (1, s) { } |
1879
|
43 |
3504
|
44 string_vector (const std::string& s) : Array<std::string> (1, s) { } |
1879
|
45 |
3504
|
46 string_vector (const string_vector& s) : Array<std::string> (s) { } |
1757
|
47 |
5880
|
48 string_vector (const std::list<std::string>& lst); |
|
49 |
2493
|
50 string_vector (const char * const *s); |
|
51 |
5275
|
52 string_vector (const char * const *s, octave_idx_type n); |
2493
|
53 |
1757
|
54 string_vector& operator = (const string_vector& s) |
2941
|
55 { |
|
56 if (this != &s) |
3504
|
57 Array<std::string>::operator = (s); |
1879
|
58 |
2941
|
59 return *this; |
|
60 } |
1757
|
61 |
|
62 ~string_vector (void) { } |
|
63 |
1811
|
64 int empty (void) const { return length () == 0; } |
1757
|
65 |
5275
|
66 octave_idx_type max_length (void) const |
2941
|
67 { |
5275
|
68 octave_idx_type n = length (); |
|
69 octave_idx_type longest = 0; |
1757
|
70 |
5275
|
71 for (octave_idx_type i = 0; i < n; i++) |
2941
|
72 { |
5275
|
73 octave_idx_type tmp = elem(i).length (); |
1757
|
74 |
2941
|
75 if (tmp > longest) |
|
76 longest = tmp; |
|
77 } |
1757
|
78 |
2941
|
79 return longest; |
|
80 } |
1757
|
81 |
5275
|
82 std::string& operator[] (octave_idx_type i) { return Array<std::string>::elem (i); } |
1757
|
83 |
5275
|
84 std::string operator[] (octave_idx_type i) const { return Array<std::string>::elem (i); } |
1757
|
85 |
4220
|
86 static int compare (const void *a_arg, const void *b_arg); |
|
87 |
4587
|
88 string_vector& qsort (bool make_uniq = false) |
2941
|
89 { |
4220
|
90 Array<std::string>::qsort (compare); |
2941
|
91 |
4587
|
92 if (make_uniq) |
2941
|
93 uniq (); |
|
94 |
|
95 return *this; |
|
96 } |
|
97 |
|
98 string_vector& uniq (void); |
1811
|
99 |
4392
|
100 string_vector& append (const std::string& s); |
|
101 |
|
102 string_vector& append (const string_vector& sv); |
|
103 |
2937
|
104 char **c_str_vec (void) const; |
|
105 |
|
106 static void delete_c_str_vec (const char * const*); |
|
107 |
5690
|
108 std::ostream& list_in_columns (std::ostream&, int width = 0) const; |
1757
|
109 }; |
|
110 |
|
111 #endif |
|
112 |
|
113 /* |
|
114 ;;; Local Variables: *** |
|
115 ;;; mode: C++ *** |
|
116 ;;; End: *** |
|
117 */ |