]> git.lyx.org Git - lyx.git/blobdiff - src/support/lyxstring.h
more changes read the ChangeLog
[lyx.git] / src / support / lyxstring.h
index 22e0b88cc3a1af0790bd57a152a3c1d3245647ec..c594ed99b5b5ebccacd424cb8ddc98d664795f94 100644 (file)
@@ -4,8 +4,8 @@
  * 
  *           LyX, The Document Processor
  *      
- *         Copyright (C) 1995 Matthias Ettrich
- *          Copyright (C) 1995-1999 The LyX Team.
+ *         Copyright 1995 Matthias Ettrich
+ *          Copyright 1995-2000 The LyX Team.
  *
  * ====================================================== */
 
@@ -25,8 +25,7 @@
 #pragma interface
 #endif
 
-#include "LOstream.h"
-#include "LIstream.h"
+#include <iosfwd>
 
 #if 0
 #include <iterator>
@@ -34,7 +33,7 @@
 
 #include <cstring> // for size_t
 
-/** A string class for LyX
+/* A string class for LyX
   
   This is a permanent String class. It is modeled closely after the C++ STL
   string class. In comparison with STL string lyxstring lack support for
@@ -91,8 +90,7 @@ When you want to copy an lyxstring, just do
 */
 class lyxstring {
 public:
-       /**@name Typedefs */
-       //@{
+       /* Typedefs */
        
        ///
        typedef char value_type;
@@ -125,7 +123,6 @@ public:
                const_reference> const_reverse_iterator;
 
 #endif
-       //@}
 
        ///
        iterator begin();
@@ -145,11 +142,10 @@ public:
        ///
        const_reverse_iterator rend() const;
 #endif
-       /**@name Constructors and Deconstructors. lyxstring has the same
+       /* Constructors and Deconstructors. lyxstring has the same
          constructors as STL, except the one using iterators, one other
          difference is that lyxstring, do not allow the optional allocator
          parameter. */
-       //@{
        
        /// "all characters" marker
        static const size_type npos;
@@ -169,23 +165,27 @@ public:
        /// lyxstring(5, 'n') -> "nnnnn"
        lyxstring(size_type n, value_type c);
 
+#if 1
        ///
-       lyxstring(iterator first, iterator last);
-       
+       lyxstring(const_iterator first, const_iterator last);
+#else
+       ///
+       template<class InputIterator>
+       lyxstring::lyxstring(InputIterator begin, InputIterator end) {
+               while (begin != end) {
+                       push_back((*begin));
+                       ++begin;
+               }
+       }
+#endif
        ///
        ~lyxstring();
 
-       //@}
-
-       
-       /**@name Size and Capacity */
-       //@{
-       
        /// number of characters
        size_type size() const;
 
        /// largest possible string
-       size_type max_size() const { return npos -1; }
+       size_type max_size() const { return npos - 1; }
 
        ///
        size_type length() const { return size(); }
@@ -205,11 +205,6 @@ public:
        ///
        void reserve(size_type res_arg = 0);
        
-       //@}
-
-       /**@name Assignment */
-       //@{
-
        ///
        lyxstring & operator=(lyxstring const &);
        
@@ -234,14 +229,21 @@ public:
        ///
        lyxstring & assign(size_type n, value_type c);
 
+#if 1
        ///
-       lyxstring & assign(iterator first, iterator last);
-       
-       //@}
+       lyxstring & assign(const_iterator first, const_iterator last);
+#else
+       ///
+       template<class InputIterator>
+       lyxstring & assign(InputIterator begin, InputIterator end) {
+               clear;
+               while (begin != end) {
+                       push_back((*begin));
+                       ++begin;
+               }
+       }
+#endif
 
-       /**@name Element Access. Since lyxstring does not use exceptions,
-         an abort is called on out-of-range access to at(). */
-       
        /// unchecked access
        const_reference operator[](size_type) const;
        
@@ -254,11 +256,6 @@ public:
        /// checked access
        reference at(size_type);
 
-       //@}
-
-       /**@name Insert */
-       //@{
-       
        // add characters after (*this)[length()-1]:
        
        ///
@@ -288,9 +285,20 @@ public:
        ///
        lyxstring & append(size_type n, value_type);
 
+#if 1
        ///
        lyxstring & append(iterator first, iterator last);
-       
+#else
+       ///
+       template<class InputIterator>
+       lyxstring & append(InputIterator begin, InputIterator end) {
+               while (begin != end) {
+                       push_back((*begin));
+                       ++begin;
+               }
+               return *this;
+       }
+#endif
        // insert characters before (*this)[pos]:
 
        ///
@@ -318,14 +326,21 @@ public:
        ///
        void insert(iterator p, size_type n , value_type c);
 
+#if 1
        ///
        void insert(iterator p, iterator first, iterator last);
+#else
+       ///
+       template<class InputIterator>
+       void insert(iterator p, InputIterator begin, InputIterator end) {
+               iterator it;
+               while (begin != end) {
+                       it = insert(p, (*begin));
+                       ++begin;
+               }
+       }
+#endif
        
-       //@}
-
-       /**@name Find */
-       //@{
-
        ///
        size_type find(lyxstring const &, size_type i = 0) const;
        
@@ -406,12 +421,6 @@ public:
        ///
        size_type find_last_not_of(value_type c, size_type i = npos) const;
 
-       //*}
-
-       
-       /**@name Replace */
-       //@{
-
        // replace [(*this)[i], (*this)[i+n]] with other characters:
 
        ///
@@ -445,10 +454,13 @@ public:
        ///
        lyxstring & replace(iterator i, iterator i2,
                            size_type n , value_type c);
-       
+
        ///
        lyxstring & replace(iterator i, iterator i2, iterator j, iterator j2);
 
+       ///
+       void swap(lyxstring & str);
+       
        /// Erase n chars from position i.
        lyxstring & erase(size_type i = 0, size_type n = npos);
 
@@ -463,30 +475,19 @@ public:
        ///
        iterator erase(iterator first, iterator last);
 
-       //@}
-
-       
-       /**@name Conversion to C-style Strings */
-       //@{
-       
        /// 
        value_type const * c_str() const;
 
-       /** Note that this is STL compilant, so you can not assume
+       /* Note that this is STL compilant, so you can not assume
          that the returned array has a trailing '\0'. */
        value_type const * data() const;
 
-       /** This one returns a verbatim copy. Not the trailing '\0'
+       /* This one returns a verbatim copy. Not the trailing '\0'
          The caller must provide a buffer with engough room.
          */
        size_type copy(value_type * buf, size_type len,
                       size_type pos = 0) const;
 
-       //@}
-
-       
-       /**@name Comparisons. Combined > and == */
-       //@{
        
        ///
        int compare(lyxstring const & str) const; 
@@ -505,18 +506,10 @@ public:
        int compare(size_type pos, size_type n, value_type const * p,
                    size_type n2 = npos) const;
        
-       //@}
-
-       
        
-       /**@name Substrings */
-       //@{
-
        ///
        lyxstring substr(size_type i = 0, size_type n = npos) const;
        
-       //@}
-
 private:
        // These three operators can be used to discover erronous use of
        // ints and strings. However a conforming C++ compiler will flag
@@ -543,7 +536,7 @@ private:
        /// A string is a pointer to it's representation
        Srep * rep;
 
-       /** Note: The empty_rep is a local static in each function that
+       /* Note: The empty_rep is a local static in each function that
            benefits from one. There is no "global" empty srep but lyxstring
            doesn't need one (no code actually relies upon a single
            empty srep).
@@ -552,7 +545,7 @@ private:
            empty_reps.
        */
 
-#ifdef DEVEL_VERSION
+#ifdef ENABLE_ASSERTIONS
        /// lyxstringInvariant is used to test the lyxstring Invariant
        friend class lyxstringInvariant;
 #endif
@@ -599,8 +592,10 @@ lyxstring operator+(lyxstring::value_type a, lyxstring const & b);
 lyxstring operator+(lyxstring const & a, lyxstring::value_type const * b);
 lyxstring operator+(lyxstring const & a, lyxstring::value_type b);
 
-istream & operator>>(istream &, lyxstring &);
-ostream & operator<<(ostream &, lyxstring const &);
-istream & getline(istream &, lyxstring &, lyxstring::value_type delim = '\n');
+void swap(lyxstring & s1, lyxstring & s2);
+
+std::istream & operator>>(std::istream &, lyxstring &);
+std::ostream & operator<<(std::ostream &, lyxstring const &);
+std::istream & getline(std::istream &, lyxstring &, lyxstring::value_type delim = '\n');
 
 #endif