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