Mercurial > hg > octave-nkf
annotate liboctave/str-vec.h @ 8870:eea0e1b45ec0
optimize string manipulation in lookfor
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 25 Feb 2009 10:21:33 +0100 |
parents | e2b4c19c455c |
children | eb63fbe60fab |
rev | line source |
---|---|
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 |
8678
e2b4c19c455c
redo changeset 4238f2600a17 with fixes to sorting
Jaroslav Hajek <highegg@gmail.com>
parents:
8671
diff
changeset
|
87 string_vector& sort (bool make_uniq = false); |
2941 | 88 |
89 string_vector& uniq (void); | |
1811 | 90 |
4392 | 91 string_vector& append (const std::string& s); |
92 | |
93 string_vector& append (const string_vector& sv); | |
94 | |
2937 | 95 char **c_str_vec (void) const; |
96 | |
97 static void delete_c_str_vec (const char * const*); | |
98 | |
5690 | 99 std::ostream& list_in_columns (std::ostream&, int width = 0) const; |
1757 | 100 }; |
101 | |
102 #endif | |
103 | |
104 /* | |
105 ;;; Local Variables: *** | |
106 ;;; mode: C++ *** | |
107 ;;; End: *** | |
108 */ |