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 |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_str_vec_h) |
|
24 #define octave_str_vec_h 1 |
|
25 |
3503
|
26 #include <iostream> |
1757
|
27 #include <string> |
|
28 |
|
29 #include "Array.h" |
|
30 |
|
31 class |
3504
|
32 string_vector : public Array<std::string> |
1757
|
33 { |
|
34 public: |
1879
|
35 |
3504
|
36 string_vector (void) : Array<std::string> () { } |
1879
|
37 |
3585
|
38 explicit string_vector (int n) : Array<std::string> (n) { } |
1879
|
39 |
3504
|
40 string_vector (const char *s) : Array<std::string> (1, s) { } |
1879
|
41 |
3504
|
42 string_vector (const std::string& s) : Array<std::string> (1, s) { } |
1879
|
43 |
3504
|
44 string_vector (const string_vector& s) : Array<std::string> (s) { } |
1757
|
45 |
2493
|
46 string_vector (const char * const *s); |
|
47 |
|
48 string_vector (const char * const *s, int n); |
|
49 |
1757
|
50 string_vector& operator = (const string_vector& s) |
2941
|
51 { |
|
52 if (this != &s) |
3504
|
53 Array<std::string>::operator = (s); |
1879
|
54 |
2941
|
55 return *this; |
|
56 } |
1757
|
57 |
|
58 ~string_vector (void) { } |
|
59 |
1811
|
60 int empty (void) const { return length () == 0; } |
1757
|
61 |
|
62 int max_length (void) const |
2941
|
63 { |
|
64 int n = length (); |
|
65 int longest = 0; |
1757
|
66 |
2941
|
67 for (int i = 0; i < n; i++) |
|
68 { |
|
69 int tmp = elem(i).length (); |
1757
|
70 |
2941
|
71 if (tmp > longest) |
|
72 longest = tmp; |
|
73 } |
1757
|
74 |
2941
|
75 return longest; |
|
76 } |
1757
|
77 |
3504
|
78 std::string& operator[] (int i) { return Array<std::string>::elem (i); } |
1757
|
79 |
3504
|
80 std::string operator[] (int i) const { return Array<std::string>::elem (i); } |
1757
|
81 |
4220
|
82 static int compare (const void *a_arg, const void *b_arg); |
|
83 |
2941
|
84 string_vector& qsort (bool make_unique = false) |
|
85 { |
4220
|
86 Array<std::string>::qsort (compare); |
2941
|
87 |
|
88 if (make_unique) |
|
89 uniq (); |
|
90 |
|
91 return *this; |
|
92 } |
|
93 |
|
94 string_vector& uniq (void); |
1811
|
95 |
4392
|
96 string_vector& append (const std::string& s); |
|
97 |
|
98 string_vector& append (const string_vector& sv); |
|
99 |
2937
|
100 char **c_str_vec (void) const; |
|
101 |
|
102 static void delete_c_str_vec (const char * const*); |
|
103 |
3504
|
104 std::ostream& list_in_columns (std::ostream&) const; |
1757
|
105 }; |
|
106 |
|
107 #endif |
|
108 |
|
109 /* |
|
110 ;;; Local Variables: *** |
|
111 ;;; mode: C++ *** |
|
112 ;;; End: *** |
|
113 */ |