~ubuntu-branches/ubuntu/utopic/tcm/utopic

« back to all changes in this revision

Viewing changes to src/dg/stringlistedge.c

  • Committer: Bazaar Package Importer
  • Author(s): Otavio Salvador
  • Date: 2003-07-03 20:08:21 UTC
  • Revision ID: james.westby@ubuntu.com-20030703200821-se4xtqx25e5miczi
Tags: upstream-2.20
ImportĀ upstreamĀ versionĀ 2.20

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
////////////////////////////////////////////////////////////////////////////////
 
2
//
 
3
// This file is part of Toolkit for Conceptual Modeling (TCM).
 
4
// (c) copyright 1998, Vrije Universiteit Amsterdam
 
5
// Author: Frank Dehne (frank@cs.vu.nl).
 
6
//
 
7
// TCM is free software; you can redistribute it and/or modify
 
8
// it under the terms of the GNU General Public License as published by
 
9
// the Free Software Foundation; either version 2 of the License, or
 
10
// (at your option) any later version.
 
11
//
 
12
// TCM is distributed in the hope that it will be useful,
 
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
// GNU General Public License for more details.
 
16
//
 
17
// You should have received a copy of the GNU General Public License
 
18
// along with TCM; if not, write to the Free Software
 
19
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 
20
// 02111-1307, USA.
 
21
////////////////////////////////////////////////////////////////////////////////
 
22
#include "inputfile.h"
 
23
#include "outputfile.h"
 
24
#include "lstring.h"
 
25
#include "stringlist.h"
 
26
#include "stringlistedge.h"
 
27
 
 
28
StringListEdge::StringListEdge(Graph *g, Subject *n1, Subject *n2): 
 
29
                Edge(g, n1, n2) {
 
30
        stringList = new List<string *>;
 
31
        stringListLabel = "Strings";
 
32
        stringLabel = "String";
 
33
}
 
34
 
 
35
StringListEdge::StringListEdge(const StringListEdge &s): Edge(s) {
 
36
        stringList = new List<string *>;
 
37
        for (s.stringList->first(); !s.stringList->done(); 
 
38
                        s.stringList->next()) {
 
39
                string *a = s.stringList->cur();
 
40
                stringList->add(new string(*a));
 
41
        }
 
42
        stringListLabel = s.stringListLabel;
 
43
        stringLabel = s.stringLabel;
 
44
}
 
45
 
 
46
StringListEdge::~StringListEdge() {
 
47
        stringList->clear();
 
48
        delete stringList;
 
49
}
 
50
 
 
51
StringListEdge::StringErrorType StringListEdge::SetString(
 
52
                const string *s, unsigned n, bool update) {
 
53
        StringList::Insert(stringList, s, n, update);
 
54
        return StringListEdge::STRING_OK;
 
55
}
 
56
 
 
57
bool StringListEdge::HasString(const string *s) {
 
58
        for (stringList->first(); !stringList->done(); 
 
59
             stringList->next()) {
 
60
                if (*stringList->cur() == *s)
 
61
                        return True;
 
62
        }
 
63
        return False;
 
64
}
 
65
 
 
66
bool StringListEdge::ReadMembers(InputFile *ifile, double format) {
 
67
        if (!Edge::ReadMembers(ifile, format))
 
68
                return False;
 
69
        string val;
 
70
        if (!ifile->ReadAttribute(&stringListLabel, &val))
 
71
                return False;
 
72
        int numItems = val.toint();
 
73
        for (int i=0; i<numItems; i++) {
 
74
                string *at = new string;
 
75
                if (!ifile->ReadStringAttribute(&stringLabel, at)) {
 
76
                        delete at;
 
77
                        return False;
 
78
                }
 
79
                stringList->add(at);
 
80
        }
 
81
        return True;
 
82
}
 
83
 
 
84
void StringListEdge::WriteMembers(OutputFile *ofile) {
 
85
        Edge::WriteMembers(ofile);
 
86
        int numItems = stringList->count();
 
87
        (*ofile) << "\t{ " << stringListLabel << " " << numItems << " }\n";
 
88
        for (int i=0; i<numItems; i++) {
 
89
                (*ofile) << "\t{ " << stringLabel << " " << '"' 
 
90
                         << *(*stringList)[i] << '"' << " }\n";
 
91
        }
 
92
}