~ubuntu-branches/ubuntu/maverick/aspectc++/maverick

« back to all changes in this revision

Viewing changes to Puma/src/common/Location.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:
19
19
#ifndef __location_h__
20
20
#define __location_h__
21
21
 
22
 
#include "Puma/SmartPtr.h"
23
 
#include "Puma/Printable.h"
24
 
#include "Puma/LocationInfo.h"
 
22
#include "Puma/Filename.h"
25
23
 
26
24
namespace Puma {
27
25
 
28
26
 
29
 
class Location : public SmartPtr, public Printable {
30
 
  LocationInfo *info () const { return (LocationInfo*)data (); }
 
27
class Location {
 
28
  Filename _filename;
 
29
  int _line;
 
30
  int _column;
31
31
 
32
32
public:
33
 
  Location () {}
34
 
  Location (Filename f, int l) { setup (f, l); }
35
 
  Location (LocationInfo *lptr) : SmartPtr (lptr) {}
36
 
  LocationInfo *operator ~ () { if (info ()) info ()->ref (); return info (); }
37
 
  void setup (Filename f, int l);
38
 
  const Filename &filename () const   { return info ()->filename (); }
39
 
  int line () const;
40
 
  bool operator == (const Location &l) const;
 
33
  Location () : _filename (), _line (0), _column (0) {}
 
34
  Location (Filename f, int l, int c = 0) { setup (f, l, c); }
 
35
  void setup (Filename f, int l, int c = 0) {
 
36
    _filename = f;
 
37
    _line     = l;
 
38
    _column   = c;
 
39
  }
 
40
  const Filename &filename () const { return _filename; }
 
41
  int line () const { return _line; }
 
42
  int column () const { return _column; }
 
43
  bool operator == (const Location &l) const {
 
44
    return filename () == l.filename () && line () == l.line () &&
 
45
      column () == l.column ();
 
46
  }
41
47
  bool operator != (const Location &l) const { return ! (*this == l); }
42
 
  bool operator < (const Location &l) const;
 
48
  bool operator < (const Location &l) const {
 
49
    // TODO: does it make sense to compare the filenames? better assert?
 
50
    if (filename () != l.filename ())
 
51
      return false;
 
52
    return line () < l.line () && column () < l.column ();
 
53
  }
 
54
};
43
55
 
44
 
  virtual void print (ostream &os) const {
45
 
    if (info ())
 
56
inline std::ostream &operator << (std::ostream &os, const Location &loc) {
46
57
#ifdef VISUAL_STUDIO
47
 
      os << filename () << "(" << line () << ")";
 
58
  os << loc.filename () << "(" << loc.line () << ")";
48
59
#else
49
 
      os << filename () << ":" << line ();
 
60
  os << loc.filename () << ":" << loc.line ();
50
61
#endif
51
 
  }
52
 
};
53
 
 
54
 
 
 
62
  return os;  
 
63
}
55
64
} // namespace Puma
56
65
 
57
66
#endif /* __location_h__ */