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 static int |
2431
|
32 str_vec_compare (const void *a_arg, const void *b_arg) |
1757
|
33 { |
3504
|
34 const std::string *a = (const std::string *) a_arg; |
|
35 const std::string *b = (const std::string *) b_arg; |
2431
|
36 |
1757
|
37 return a->compare (*b); |
|
38 } |
|
39 |
|
40 class |
3504
|
41 string_vector : public Array<std::string> |
1757
|
42 { |
|
43 public: |
1879
|
44 |
3504
|
45 string_vector (void) : Array<std::string> () { } |
1879
|
46 |
3504
|
47 string_vector (int n) : Array<std::string> (n) { } |
1879
|
48 |
3504
|
49 string_vector (const char *s) : Array<std::string> (1, s) { } |
1879
|
50 |
3504
|
51 string_vector (const std::string& s) : Array<std::string> (1, s) { } |
1879
|
52 |
3504
|
53 string_vector (const string_vector& s) : Array<std::string> (s) { } |
1757
|
54 |
2493
|
55 string_vector (const char * const *s); |
|
56 |
|
57 string_vector (const char * const *s, int n); |
|
58 |
1757
|
59 string_vector& operator = (const string_vector& s) |
2941
|
60 { |
|
61 if (this != &s) |
3504
|
62 Array<std::string>::operator = (s); |
1879
|
63 |
2941
|
64 return *this; |
|
65 } |
1757
|
66 |
|
67 ~string_vector (void) { } |
|
68 |
1811
|
69 int empty (void) const { return length () == 0; } |
1757
|
70 |
|
71 int max_length (void) const |
2941
|
72 { |
|
73 int n = length (); |
|
74 int longest = 0; |
1757
|
75 |
2941
|
76 for (int i = 0; i < n; i++) |
|
77 { |
|
78 int tmp = elem(i).length (); |
1757
|
79 |
2941
|
80 if (tmp > longest) |
|
81 longest = tmp; |
|
82 } |
1757
|
83 |
2941
|
84 return longest; |
|
85 } |
1757
|
86 |
3504
|
87 std::string& operator[] (int i) { return Array<std::string>::elem (i); } |
1757
|
88 |
3504
|
89 std::string operator[] (int i) const { return Array<std::string>::elem (i); } |
1757
|
90 |
2941
|
91 string_vector& qsort (bool make_unique = false) |
|
92 { |
3504
|
93 Array<std::string>::qsort (str_vec_compare); |
2941
|
94 |
|
95 if (make_unique) |
|
96 uniq (); |
|
97 |
|
98 return *this; |
|
99 } |
|
100 |
|
101 string_vector& uniq (void); |
1811
|
102 |
2937
|
103 char **c_str_vec (void) const; |
|
104 |
|
105 static void delete_c_str_vec (const char * const*); |
|
106 |
3504
|
107 std::ostream& list_in_columns (std::ostream&) const; |
1757
|
108 }; |
|
109 |
|
110 #endif |
|
111 |
|
112 /* |
|
113 ;;; Local Variables: *** |
|
114 ;;; mode: C++ *** |
|
115 ;;; End: *** |
|
116 */ |