xquery_stack_trace.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2006-2008 The FLWOR Foundation.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  * 
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #ifndef ZORBA_XQUERY_STACK_TRACE_API_H
00018 #define ZORBA_XQUERY_STACK_TRACE_API_H
00019 
00020 #include <string>
00021 #include <vector>
00022 
00023 #include <zorba/internal/qname.h>
00024 
00025 namespace zorba {
00026 
00027 class XQueryStackTrace;
00028 
00029 namespace serialization {
00030   class Archiver;
00031   void operator&( Archiver&, XQueryStackTrace& );
00032 }
00033 
00034 ///////////////////////////////////////////////////////////////////////////////
00035 
00036 class XQueryStackTrace {
00037 public:
00038   typedef internal::VariableQName<std::string> fn_name_type;
00039   typedef unsigned short fn_arity_type;
00040   typedef unsigned line_type;
00041   typedef unsigned short column_type;
00042 
00043   class Entry {
00044   public:
00045     Entry( fn_name_type const &fn_name, fn_arity_type fn_arity,
00046            char const *file_name, line_type line, column_type column,
00047            line_type line_end, column_type column_end);
00048 
00049     fn_name_type const& getFnName() const {
00050       return fn_name_;
00051     }
00052 
00053     fn_arity_type const& getFnArity() const {
00054       return fn_arity_;
00055     }
00056 
00057     std::string const& getFileName() const {
00058       return filename_;
00059     }
00060 
00061     line_type getLine() const {
00062       return line_;
00063     }
00064 
00065     column_type getColumn() const {
00066       return col_;
00067     }
00068 
00069     line_type getLineEnd() const {
00070       return line_end_;
00071     }
00072 
00073     column_type getColumnEnd() const {
00074       return col_end_;
00075     }
00076 
00077     fn_name_type& getFnNameRef()  {
00078       return fn_name_;
00079     }
00080 
00081     fn_arity_type& getFnArityRef() {
00082       return fn_arity_;
00083     }
00084 
00085     std::string& getFileNameRef() {
00086       return filename_;
00087     }
00088 
00089     line_type& getLineRef() {
00090       return line_;
00091     }
00092 
00093     column_type& getColumnRef() {
00094       return col_;
00095     }
00096 
00097     line_type& getLineEndRef() {
00098       return line_end_;
00099     }
00100 
00101     column_type& getColumnEndRef() {
00102       return col_end_;
00103     }
00104 
00105   private:
00106     fn_name_type fn_name_;
00107     fn_arity_type fn_arity_;
00108     std::string filename_;
00109     line_type line_;
00110     column_type col_;
00111     line_type line_end_;
00112     column_type col_end_;
00113   public:
00114     // for plan serialization
00115     Entry();
00116   };
00117 
00118   typedef std::vector<Entry> trace_t;
00119   typedef trace_t::size_type size_type;
00120   typedef trace_t::const_iterator const_iterator;
00121   typedef trace_t::const_reverse_iterator const_reverse_iterator;
00122 
00123   bool empty() const {
00124     return trace_.empty();
00125   }
00126 
00127   const_iterator begin() const {
00128     return trace_.begin();
00129   }
00130 
00131   const_iterator end() const {
00132     return trace_.end();
00133   }
00134 
00135   const_reverse_iterator rbegin() const {
00136     return trace_.rbegin();
00137   }
00138 
00139   const_reverse_iterator rend() const {
00140     return trace_.rend();
00141   }
00142 
00143   void push( Entry const &entry );
00144 
00145   size_type size() const {
00146     return trace_.size();
00147   }
00148 
00149 private:
00150   trace_t trace_;
00151 
00152   friend void serialization::operator&( serialization::Archiver&,
00153                                         XQueryStackTrace& );
00154 };
00155 
00156 ///////////////////////////////////////////////////////////////////////////////
00157 
00158 } // namespace zorba
00159 
00160 #endif /* ZORBA_XQUERY_STACK_TRACE_API_H */
00161 /*
00162  * Local variables:
00163  * mode: c++
00164  * End:
00165  */
00166 /* vim:set et sw=2 ts=2: */
blog comments powered by Disqus