File: string_list.hpp

package info (click to toggle)
aspell 0.60.6-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 10,000 kB
  • ctags: 4,862
  • sloc: sh: 48,145; cpp: 22,153; perl: 1,546; ansic: 1,535; makefile: 684; sed: 16
file content (100 lines) | stat: -rw-r--r-- 2,315 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// This file is part of The New Aspell
// Copyright (C) 2001 by Kevin Atkinson under the GNU LGPL license
// version 2.0 or 2.1.  You should have received a copy of the LGPL
// license along with this library if you did not you can find
// it at http://www.gnu.org/.
#ifndef STRING_LIST_HP_HEADER
#define STRING_LIST_HP_HEADER

#include "string.hpp"
#include "string_enumeration.hpp"
#include "mutable_container.hpp"
#include "posib_err.hpp"
#include <stdio.h>
#include <cstdio>

namespace acommon {

  struct StringListNode {
    // private data structure
    // default copy & destructor unsafe
    String           data;
    StringListNode * next;
    StringListNode(ParmStr str,  StringListNode * n = 0)
      : data(str), next(n) {
    }
  };

  class StringListEnumeration : public StringEnumeration {
    // default copy and destructor safe
  private:
    StringListNode * n_;
  public:
    StringEnumeration * clone() const;
    void assign(const StringEnumeration *);

    StringListEnumeration(StringListNode * n) : n_(n) {}
    const char * next() {
      const char * temp;
      if (n_ == 0) {
	temp = 0;
      } else {
	temp = n_->data.c_str();
	n_ = n_->next;
      }
      return temp;
    }
    bool at_end() const {
      return n_ == 0;
    }
  };


  class StringList : public MutableContainer {
    // copy and destructor provided
  private:
    StringListNode * first;

    StringListNode * * find (ParmStr str);
    void copy(const StringList &);
    void destroy();
  public:
    friend bool operator==(const StringList &, const StringList &);
    StringList() : first(0) {}
    StringList(const StringList & other) 
    {
      copy(other);
    }
    StringList & operator= (const StringList & other)
    {
      destroy();
      copy(other);
      return *this;
    }
    virtual ~StringList() 
    {
      destroy();
    }

    StringList * clone() const;
    void assign(const StringList *);

    PosibErr<bool> add(ParmStr);
    PosibErr<bool> remove(ParmStr);
    PosibErr<void> clear();

    StringEnumeration * elements() const;
    StringListEnumeration elements_obj() const 
    {
      return StringListEnumeration(first);
    }

    bool empty() const { return first == 0; }
    unsigned int size() const { abort(); return 0; }

  };

  StringList * new_string_list();

}
#endif