~ubuntu-branches/ubuntu/intrepid/tcm/intrepid

« back to all changes in this revision

Viewing changes to src/dg/stringlistnode2.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 "stringlistnode2.h"
 
27
 
 
28
StringListNode2::StringListNode2(Graph *g): StringListNode(g) {
 
29
        stringList2 = new List<string *>;
 
30
        stringListLabel2 = "Strings2";
 
31
        stringLabel2 = "String2";
 
32
}
 
33
 
 
34
StringListNode2::StringListNode2(const StringListNode2 &s): StringListNode(s) {
 
35
        stringList2 = new List<string *>;
 
36
        for (s.stringList2->first(); !s.stringList2->done(); 
 
37
                        s.stringList2->next()) {
 
38
                string *a = s.stringList2->cur();
 
39
                stringList2->add(new string(*a));
 
40
        }
 
41
        stringListLabel2 = s.stringListLabel2;
 
42
        stringLabel2 = s.stringLabel2;
 
43
}
 
44
 
 
45
StringListNode2::~StringListNode2() {
 
46
        stringList2->clear();
 
47
        delete stringList2;
 
48
}
 
49
 
 
50
bool StringListNode2::HasString2(const string *s) {
 
51
        for (stringList2->first(); !stringList2->done();
 
52
             stringList2->next()) {
 
53
                if (*stringList2->cur() == *s)
 
54
                        return True;
 
55
        }
 
56
        return False;
 
57
}
 
58
 
 
59
StringListNode2::StringErrorType StringListNode2::SetString2(
 
60
                const string *s, unsigned n, bool update) {
 
61
        StringList::Insert(stringList2, s, n, update);
 
62
        return StringListNode::STRING_OK;
 
63
}
 
64
 
 
65
bool StringListNode2::ReadMembers(InputFile *ifile, double format) {
 
66
        if (!StringListNode::ReadMembers(ifile, format))
 
67
                return False;
 
68
        string val;
 
69
        if (!ifile->ReadAttribute(&stringListLabel2, &val))
 
70
                return False;
 
71
        int numItems = val.toint();
 
72
        for (int i=0; i<numItems; i++) {
 
73
                string *at = new string;
 
74
                if (!ifile->ReadStringAttribute(&stringLabel2, at)) {
 
75
                        delete at;
 
76
                        return False;
 
77
                }
 
78
                stringList2->add(at);
 
79
        }
 
80
        return True;
 
81
}
 
82
 
 
83
void StringListNode2::WriteMembers(OutputFile *ofile) {
 
84
        StringListNode::WriteMembers(ofile);
 
85
        int numItems = stringList2->count();
 
86
        (*ofile) << "\t{ " << stringListLabel2 << " " << numItems << " }\n";
 
87
        for (int i=0; i<numItems; i++) {
 
88
                (*ofile) << "\t{ " << stringLabel2 << " " << '"' 
 
89
                         << *(*stringList2)[i] << '"' << " }\n";
 
90
        }
 
91
}