1 /**
2  * Copyright (c) 2019, Timothy Stack
3  *
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * * Redistributions of source code must retain the above copyright notice, this
10  * list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  * * Neither the name of Timothy Stack nor the names of its contributors
15  * may be used to endorse or promote products derived from this software
16  * without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY
19  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
22  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef lnav_file_range_hh
31 #define lnav_file_range_hh
32 
33 #include <sys/types.h>
34 
35 #include "intern_string.hh"
36 
37 using file_off_t = int64_t;
38 using file_size_t = uint64_t;
39 using file_ssize_t = int64_t;
40 
41 class file_range {
42 public:
43     file_off_t fr_offset{0};
44     file_ssize_t fr_size{0};
45 
clear()46     void clear() {
47         this->fr_offset = 0;
48         this->fr_size = 0;
49     }
50 
next_offset() const51     ssize_t next_offset() const {
52         return this->fr_offset + this->fr_size;
53     }
54 
empty() const55     bool empty() const {
56         return fr_size == 0;
57     }
58 };
59 
60 struct source_location {
source_locationsource_location61     source_location()
62         : sl_source(intern_string::lookup("unknown")),
63           sl_line_number(-1) {
64     }
65 
source_locationsource_location66     source_location(intern_string_t source, int line)
67         : sl_source(source), sl_line_number(line) {};
68 
69     intern_string_t sl_source;
70     int sl_line_number;
71 };
72 
73 #endif
74