• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

TsBuilder.h

Go to the documentation of this file.
00001 # if ! defined(TS_CONFIG_BUILDER_HEADER)
00002 # define TS_CONFIG_BUILDER_HEADER
00003 
00004 /** @file
00005 
00006     Header for handler for parsing events.
00007 
00008     @section license License
00009 
00010     Licensed to the Apache Software Foundation (ASF) under one
00011     or more contributor license agreements.  See the NOTICE file
00012     distributed with this work for additional information
00013     regarding copyright ownership.  The ASF licenses this file
00014     to you under the Apache License, Version 2.0 (the
00015     "License"); you may not use this file except in compliance
00016     with the License.  You may obtain a copy of the License at
00017 
00018     http://www.apache.org/licenses/LICENSE-2.0
00019 
00020     Unless required by applicable law or agreed to in writing, software
00021     distributed under the License is distributed on an "AS IS" BASIS,
00022     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00023     See the License for the specific language governing permissions and
00024     limitations under the License.
00025  */
00026 
00027 # include "TsValue.h"
00028 # include "TsConfigTypes.h"
00029 # include "TsConfigParseEvents.h"
00030 
00031 namespace ts { namespace config {
00032 
00033 /** Class to build the configuration table from parser events.
00034  */
00035 class Builder {
00036 public:
00037     typedef Builder self;
00038     struct Handler {
00039         self* _ptr; ///< Pointer to Builder instance.
00040         /// Pointer to method to invoke for this event.
00041         void (self::*_method)(Token const& token);
00042 
00043         /// Default constructor.
00044         Handler();
00045     };
00046 
00047     /// Default constructor.
00048     Builder();
00049     /// Destructor.
00050     virtual ~Builder() {}
00051     /// Construct with existing configuration.
00052     Builder(Configuration const& config);
00053     /// Build the table.
00054     /// @return The configuration or error status.
00055     Rv<Configuration> build(
00056         Buffer const& buffer ///< Input text.
00057     );
00058 protected:
00059     /// Dispatch table for parse events.
00060     Handler _dispatch[TS_CONFIG_N_EVENT_TYPES];
00061     /// Event handler table for the parser.
00062     TsConfigHandlers _handlers;
00063     /// Dispatch methods
00064     virtual void groupOpen(Token const& token);
00065     virtual void groupClose(Token const& token);
00066     virtual void groupName(Token const& token);
00067     virtual void listOpen(Token const& token);
00068     virtual void listClose(Token const& token);
00069     virtual void pathOpen(Token const& token);
00070     virtual void pathTag(Token const& token);
00071     virtual void pathIndex(Token const& token);
00072     virtual void pathClose(Token const& token);
00073     virtual void literalValue(Token const& token);
00074     virtual void invalidToken(Token const& token);
00075     /// Syntax error handler
00076     virtual int syntaxError(char const* text);
00077     /// Static method to handle parser event callbacks.
00078     static void dispatch(void* data, Token* token);
00079     /// Static method for syntax errors.
00080     static int syntaxErrorDispatch(void* data, char const* text);
00081 
00082     // Building state.
00083     Configuration _config; ///< Configuration to update.
00084     Errata _errata; ///< Error accumulator.
00085     Value _v; ///< Current value.
00086     Buffer _name; ///< Pending group name, if any.
00087     Buffer _extent; ///< Accumulator for multi-token text.
00088     Location _loc; ///< Cache for multi-token text.
00089     Path _path; ///< Path accumulator
00090 
00091     /// Initialization, called from constructors.
00092     self& init();
00093 };
00094 
00095 inline Builder::Handler::Handler() : _ptr(0), _method(0) { }
00096 inline Builder::Builder() { this->init(); }
00097 inline Builder::Builder(Configuration const& config) : _config(config) { this->init(); }
00098 
00099 }} // namespace ts::config
00100 
00101 # endif // TS_CONFIG_BUILDER_HEADER

Generated by  doxygen 1.7.1