Canola  0.8.D001
lib/location.h
Go to the documentation of this file.
00001 //
00002 // canola - canon canola 1614p emulator
00003 // Copyright (C) 2011 Peter Miller
00004 //
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License, version 3, as
00007 // published by the Free Software Foundation.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License along
00015 // with this program. If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 
00018 #ifndef LIB_LOCATION_H
00019 #define LIB_LOCATION_H
00020 
00021 #include <lib/ac/stddef.h>
00022 #include <string>
00023 #include <boost/shared_ptr.hpp>
00024 
00025 #include <lib/format_printf.h>
00026 
00032 class location
00033 {
00034 public:
00035     typedef boost::shared_ptr<location> pointer;
00036 
00040     virtual ~location();
00041 
00055     static pointer create(const std::string &filename, int line_number,
00056         size_t byte_start, size_t byte_length);
00057 
00058     static location::pointer span(const location::pointer &from,
00059         const location::pointer &to);
00060 
00061     std::string get_filename(void) const { return filename; }
00062     int get_line_number(void) const { return line_number; }
00063     size_t get_start(void) const { return byte_start; }
00064     size_t get_end(void) const { return (byte_start + byte_length); }
00065 
00067     std::string representation(void) const;
00068 
00069 private:
00083     location(const std::string &filename, int line_number, size_t byte_start,
00084         size_t byte_length);
00085 
00090     std::string filename;
00091 
00096     int line_number;
00097 
00102     size_t byte_start;
00103 
00108     size_t byte_length;
00109 
00114     location();
00115 
00123     location(const location &rhs);
00124 
00132     location &operator=(const location &rhs);
00133 };
00134 
00135 #endif // LIB_LOCATION_H