1 /*
2  * Copyright 2006-2008 The FLWOR Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
17 #ifndef ZORBA_QUERY_LOC_H
18 #define ZORBA_QUERY_LOC_H
19 
20 #include "zorbatypes/zstring.h"
21 
22 
23 namespace zorba {
24 
25 namespace serialization
26 {
27   class Archiver;
28 }
29 
30 /**
31  * Class to save the query location of zorba elements that correspond to a code
32  * snipped in the query.
33  * This class is a replacement of yy::location which is generated by the bison
34  * parser generator. yy::location is used as few as possible in zorba to reduced
35  * dependencies to the parser.
36  */
37 class QueryLoc
38 {
39 public:
40   static QueryLoc null;
41 
42 public:
43   zstring      theFilename;
44   unsigned int theLineBegin;
45   unsigned int theColumnBegin;
46   unsigned int theLineEnd;
47   unsigned int theColumnEnd;
48 
49 public:
50   QueryLoc();
51 
52   QueryLoc( zstring const &filename, unsigned lineBegin, unsigned lineEnd,
53             unsigned columnBegin = 0, unsigned columnEnd = 0 );
54 
55 public:
getFilename()56   const zstring& getFilename() const { return theFilename; }
57 
setFilename(const zstring & aFilename)58   void setFilename(const zstring& aFilename) { theFilename = aFilename; }
59 
setFilename(const char * aFilename)60   void setFilename(const char* aFilename) { theFilename = aFilename; }
61 
getLineBegin()62   unsigned int getLineBegin() const { return theLineBegin; }
63 
setLineBegin(unsigned int aLineBegin)64   void setLineBegin(unsigned int aLineBegin) { theLineBegin = aLineBegin; }
65 
getLineEnd()66   unsigned int getLineEnd() const { return theLineEnd; }
67 
setLineEnd(unsigned int aLineEnd)68   void setLineEnd(unsigned int aLineEnd) { theLineEnd = aLineEnd; }
69 
getColumnBegin()70   unsigned int getColumnBegin() const { return theColumnBegin; }
71 
getColumnEnd()72   unsigned int getColumnEnd() const { return theColumnEnd; }
73 
setColumnBegin(unsigned int aColumnBegin)74   void setColumnBegin(unsigned int aColumnBegin) { theColumnBegin = aColumnBegin; }
75 
setColumnEnd(unsigned int aColumnEnd)76   void setColumnEnd(unsigned int aColumnEnd) { theColumnEnd = aColumnEnd; }
77 
getLineno()78   unsigned int getLineno() const { return getLineBegin(); }
79 
80   bool equals(const QueryLoc& loc) const;
81 
82   bool operator==(const QueryLoc& loc) const
83   {
84     return equals(loc);
85   }
86 
87   bool operator<(const QueryLoc& loc) const
88   {
89     return theLineBegin < loc.getLineBegin();
90   }
91 };
92 
93 
94 std::ostream& operator<< (std::ostream& aOstr, const QueryLoc& aQueryLoc);
95 
96 } // namespace zorba
97 
98 #endif
99 /* vim:set et sw=2 ts=2: */
100