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

« back to all changes in this revision

Viewing changes to src/sd/dv/classnode.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 1996, 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 "classnode.h"
 
23
#include "lstring.h"
 
24
#include "crgraph.h"
 
25
 
 
26
ClassNode::ClassNode(CRGraph *g): StringListNode2(g) {
 
27
        SetStringLabel("Attribute");
 
28
        SetStringListLabel("Attributes");
 
29
        SetStringLabel2("Operation");
 
30
        SetStringListLabel2("Operations");
 
31
}
 
32
 
 
33
ClassNode::TextErrType ClassNode::SetAttribute(
 
34
                const string *s, unsigned n, bool update) {
 
35
        if (*s != "" && s->letters()==0)
 
36
                return ClassNode::IMPOSSIBLE_ATTRIBUTE;
 
37
        if (HasOperation(s))
 
38
                return ClassNode::OPERATION_EXISTS;
 
39
        if (HasAttribute(s)) {
 
40
                if (n >= NrAttributes() || *GetAttribute(n) != *s || 
 
41
                    !update)
 
42
                        return ClassNode::ATTRIBUTE_EXISTS;
 
43
        }
 
44
        SetString(s, n, update);
 
45
        return ClassNode::MEMBER_OK;
 
46
}
 
47
 
 
48
ClassNode::TextErrType ClassNode::SetOperation(
 
49
                const string *s, unsigned n, bool update) {
 
50
        if (*s != "" && s->letters()==0)
 
51
                return ClassNode::IMPOSSIBLE_ATTRIBUTE;
 
52
        if (HasAttribute(s))
 
53
                return ClassNode::ATTRIBUTE_EXISTS;
 
54
        if (HasOperation(s)) {
 
55
                if (n >= NrOperations() || *GetOperation(n) != *s || !update)
 
56
                        return ClassNode::OPERATION_EXISTS;
 
57
        }
 
58
        SetString2(s, n, update);
 
59
        return ClassNode::MEMBER_OK;
 
60
}
 
61
 
 
62
const string *ClassNode::GetAttribute(unsigned n) {
 
63
        return GetString(n);
 
64
}
 
65
 
 
66
unsigned ClassNode::NrAttributes() {
 
67
        return NrStrings();
 
68
}
 
69
 
 
70
const string *ClassNode::GetOperation(unsigned n) {
 
71
        return GetString2(n);
 
72
}
 
73
 
 
74
unsigned ClassNode::NrOperations() {
 
75
        return NrStrings2();
 
76
}
 
77
 
 
78
bool ClassNode::HasAttribute(const string *s) {
 
79
        return HasString(s);
 
80
}
 
81
 
 
82
bool ClassNode::HasOperation(const string *s) {
 
83
        return HasString2(s);
 
84
}
 
85
 
 
86
bool ClassNode::ReadMembers(InputFile *ifile, double format) {
 
87
        string s1, s2; 
 
88
        if (format < 1.27) {
 
89
                s1 = *GetStringListLabel2();
 
90
                s2 = *GetStringLabel2();
 
91
                SetStringListLabel2("Actions");
 
92
                SetStringLabel2("Action");
 
93
        }
 
94
        bool b = StringListNode2::ReadMembers(ifile, format);
 
95
        if (format < 1.27) {
 
96
                SetStringListLabel2(&s1);
 
97
                SetStringLabel2(&s2);
 
98
        }
 
99
        return b;
 
100
}