~ubuntu-branches/ubuntu/vivid/regina-normal/vivid

« back to all changes in this revision

Viewing changes to engine/packet/nscript.cpp

  • Committer: Package Import Robot
  • Author(s): Ben Burton
  • Date: 2013-11-02 11:44:32 UTC
  • mfrom: (1.2.8)
  • Revision ID: package-import@ubuntu.com-20131102114432-acgci6b1pb2hjl8q
Tags: 4.95-1
* New upstream release.
* The python module is now installed in a standard location beneath
  /usr/lib/python2.7/dist-packages.
* Switched python packaging from python-support to dh_python2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
 
41
41
namespace regina {
42
42
 
43
 
namespace {
44
 
    const std::string emptyString;
45
 
}
46
 
 
47
43
const std::string& NScript::getVariableName(unsigned long index) const {
48
 
    std::map<std::string, std::string>::const_iterator it = variables.begin();
 
44
    std::map<std::string, NPacket*>::const_iterator it = variables.begin();
49
45
    advance(it, index);
50
46
    return (*it).first;
51
47
}
52
48
 
53
 
const std::string& NScript::getVariableValue(unsigned long index) const {
54
 
    std::map<std::string, std::string>::const_iterator it = variables.begin();
 
49
NPacket* NScript::getVariableValue(unsigned long index) const {
 
50
    std::map<std::string, NPacket*>::const_iterator it = variables.begin();
55
51
    advance(it, index);
56
52
    return (*it).second;
57
53
}
58
54
 
59
 
const std::string& NScript::getVariableValue(const std::string& name) const {
60
 
    std::map<std::string, std::string>::const_iterator it =
61
 
        variables.find(name);
 
55
NPacket* NScript::getVariableValue(const std::string& name) const {
 
56
    std::map<std::string, NPacket*>::const_iterator it = variables.find(name);
62
57
    if (it == variables.end())
63
 
        return emptyString;
 
58
        return 0;
64
59
    return (*it).second;
65
60
}
66
61
 
 
62
void NScript::removeVariable(const std::string& name) {
 
63
    std::map<std::string, NPacket*>::iterator it = variables.find(name);
 
64
    if (it == variables.end())
 
65
        return;
 
66
 
 
67
    if (it->second)
 
68
        it->second->unlisten(this);
 
69
 
 
70
    ChangeEventSpan span(this);
 
71
    variables.erase(it);
 
72
}
 
73
 
67
74
void NScript::writeTextLong(std::ostream& o) const {
68
75
    if (variables.empty())
69
76
        o << "No variables.\n";
70
77
    else {
71
 
        for (std::map<std::string, std::string>::const_iterator vit =
72
 
                variables.begin(); vit != variables.end(); vit++)
73
 
            o << "Variable: " << (*vit).first << " = " << (*vit).second << '\n';
 
78
        for (std::map<std::string, NPacket*>::const_iterator vit =
 
79
                variables.begin(); vit != variables.end(); vit++) {
 
80
            o << "Variable: " << vit->first << " = ";
 
81
            if (vit->second)
 
82
                o << vit->second->getPacketLabel() << '\n';
 
83
            else
 
84
                o << "(null)" << '\n';
 
85
        }
74
86
    }
75
87
    o << '\n';
76
88
    copy(lines.begin(), lines.end(),
87
99
void NScript::writeXMLPacketData(std::ostream& out) const {
88
100
    using regina::xml::xmlEncodeSpecialChars;
89
101
 
90
 
    for (std::map<std::string, std::string>::const_iterator vit =
91
 
            variables.begin(); vit != variables.end(); vit++)
 
102
    for (std::map<std::string, NPacket*>::const_iterator vit =
 
103
            variables.begin(); vit != variables.end(); vit++) {
92
104
        out << "  <var name=\"" << xmlEncodeSpecialChars((*vit).first)
93
 
            << "\" value=\"" << xmlEncodeSpecialChars((*vit).second)
94
 
            << "\"/>\n";
 
105
            << "\" valueid=\"";
 
106
        if (vit->second)
 
107
            out << vit->second->internalID();
 
108
        out << "\" value=\"";
 
109
        if (vit->second)
 
110
            out << xmlEncodeSpecialChars(vit->second->getPacketLabel());
 
111
        out << "\"/>\n";
 
112
    }
95
113
 
96
114
    for (std::vector<std::string>::const_iterator it = lines.begin();
97
115
            it != lines.end(); it++)
98
116
        out << "  <line>" << xmlEncodeSpecialChars(*it) << "</line>\n";
99
117
}
100
118
 
 
119
void NScript::packetToBeDestroyed(NPacket* packet) {
 
120
    // We know the script will change, because one of our variables is
 
121
    // listening on this packet.
 
122
    ChangeEventSpan span(this);
 
123
    for (std::map<std::string, NPacket*>::iterator vit =
 
124
            variables.begin(); vit != variables.end(); vit++)
 
125
        if (vit->second == packet)
 
126
            vit->second = 0;
 
127
}
 
128
 
101
129
} // namespace regina
102
130