~ubuntu-branches/ubuntu/quantal/aspectc++/quantal

« back to all changes in this revision

Viewing changes to AspectC++/JoinPointModelElement.h

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2008-04-10 17:40:52 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20080410174052-xdnsm7oi8hauyyf1
Tags: 1.0pre4~svn.20080409+dfsg-3
Fix another missing include, this time in Ag++/StdSystem.cc

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// This file is part of the AspectC++ compiler 'ac++'.
 
2
// Copyright (C) 1999-2003  The 'ac++' developers (see aspectc.org)
 
3
//                                                                
 
4
// This program is free software;  you can redistribute it and/or 
 
5
// modify it under the terms of the GNU General Public License as 
 
6
// published by the Free Software Foundation; either version 2 of 
 
7
// the License, or (at your option) any later version.            
 
8
//                                                                
 
9
// This program is distributed in the hope that it will be useful,
 
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of 
 
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
 
12
// GNU General Public License for more details.                   
 
13
//                                                                
 
14
// You should have received a copy of the GNU General Public      
 
15
// License along with this program; if not, write to the Free     
 
16
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
 
17
// MA  02111-1307  USA                                            
 
18
 
 
19
#ifndef __join_point_model_element_h__
 
20
#define __join_point_model_element_h__
 
21
 
 
22
#include <set>
 
23
using std::set;
 
24
#include <vector>
 
25
using std::vector;
 
26
#include <map>
 
27
using std::map;
 
28
#include <sstream>
 
29
using std::istringstream;
 
30
 
 
31
typedef vector<class JoinPointModelElement *> IdElementMap;
 
32
 
 
33
// The base class of all join point model elements
 
34
 
 
35
class JoinPointModelElement {
 
36
  // needed for reconciling the translation unit model with the project model
 
37
  mutable bool _ref;
 
38
  mutable JoinPointModelElement *_partner;
 
39
  
 
40
  /// a unique id for each joinpoint location
 
41
  int _id;
 
42
  
 
43
  /// map needed to locate model elements based on their ID
 
44
  IdElementMap *_map;
 
45
 
 
46
  /// assigned JPID for code generation
 
47
  int _assigned_id;
 
48
    
 
49
public:
 
50
  JoinPointModelElement () : _ref (false), _partner (0), _id (-1), _map (0),
 
51
    _assigned_id (-1) {}
 
52
  JoinPointModelElement (const JoinPointModelElement &copy) :
 
53
    _ref (false), _partner (0), _id (-1), _map (0), _assigned_id (-1) {}
 
54
  void assigned_id (int id) { _assigned_id = id; }
 
55
  int assigned_id () const { return _assigned_id; }
 
56
  bool is_ref () const { return _ref; }
 
57
  void ref (bool r = true) const { _ref = r; }
 
58
  JoinPointModelElement *partner () const { return _partner; }
 
59
  void partner (JoinPointModelElement *p) const { _partner = p; }
 
60
  int id () const { return _id; }
 
61
  void id (int new_id) {
 
62
    if (!_map) {
 
63
      cout << "element without map" << endl;
 
64
    }
 
65
    else {
 
66
      if (new_id == _id)
 
67
        return;
 
68
      if (_id != -1) {
 
69
        (*_map)[_id] = 0;
 
70
      }
 
71
      while ((unsigned)new_id >= _map->size ())
 
72
        _map->push_back (0);
 
73
      (*_map)[new_id] = this;
 
74
    }
 
75
    _id = new_id;
 
76
  }
 
77
  IdElementMap *map () const { return _map; }
 
78
  JoinPointModelElement *map (int id) const { return (*_map)[id]; }
 
79
  void map (IdElementMap *map) { _map = map; }
 
80
};
 
81
 
 
82
// container for element IDs
 
83
 
 
84
class IdSet : public set<int> {
 
85
  typedef set<int> _Base;
 
86
public:
 
87
  string to_string () const {
 
88
    if (_Base::empty ())
 
89
      return "";
 
90
    ostringstream out;
 
91
    for (_Base::iterator i = _Base::begin (); i != _Base::end (); ++i) {
 
92
      if (i != _Base::begin ())
 
93
        out << " ";
 
94
      out << *i;
 
95
    }
 
96
    return out.str ();
 
97
  }
 
98
  bool from_string (const string &id_str) {
 
99
    istringstream in (id_str, istringstream::in);
 
100
    int id;
 
101
    while (!in.eof ()) {
 
102
      in >> id;
 
103
      if (in.fail ())
 
104
        return false;
 
105
      else
 
106
        insert (id);
 
107
    }
 
108
    return true;
 
109
  }
 
110
};
 
111
 
 
112
#endif // __join_point_model_element_h__