TOBI SignalServer  0.1
/home/breidi/Dropbox/signalserver/include/config/xml_parser.h
Go to the documentation of this file.
00001 /*
00002     This file is part of the TOBI SignalServer.
00003 
00004     Commercial Usage
00005     Licensees holding valid Graz University of Technology Commercial
00006     licenses may use this file in accordance with the Graz University
00007     of Technology Commercial License Agreement provided with the
00008     Software or, alternatively, in accordance with the terms contained in
00009     a written agreement between you and Graz University of Technology.
00010 
00011     --------------------------------------------------
00012 
00013     GNU General Public License Usage
00014     Alternatively, this file may be used under the terms of the GNU
00015     General Public License version 3.0 as published by the Free Software
00016     Foundation and appearing in the file gpl.txt included in the
00017     packaging of this file.  Please review the following information to
00018     ensure the GNU General Public License version 3.0 requirements will be
00019     met: http://www.gnu.org/copyleft/gpl.html.
00020 
00021     In case of GNU General Public License Usage ,the TOBI SignalServer
00022     is distributed in the hope that it will be useful,
00023     but WITHOUT ANY WARRANTY; without even the implied warranty of
00024     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00025     GNU General Public License for more details.
00026 
00027     You should have received a copy of the GNU General Public License
00028     along with the TOBI SignalServer. If not, see <http://www.gnu.org/licenses/>.
00029 
00030     Copyright 2010 Graz University of Technology
00031     Contact: SignalServer@tobi-project.org
00032 */
00033 
00043 #ifndef XMLPARSER_H
00044 #define XMLPARSER_H
00045 
00046 // ticpp
00047 #include "ticpp/ticpp.h"
00048 
00049 // stl
00050 #include <iostream>
00051 #include <vector>
00052 #include <string>
00053 #include <map>
00054 
00055 // boost
00056 #include <boost/lexical_cast.hpp>
00057 
00058 #include "tia/constants.h"
00059 
00060 namespace tobiss
00061 {
00062 
00063 //---------------------------------------------------------------------------------------
00064 
00070 class XMLParser
00071 {
00072   public:
00076     XMLParser()
00077     {
00078       #ifdef DEBUG
00079       std::cout << " XMLParser: Default Constructor" << std::endl;
00080       #endif
00081     }
00087     XMLParser(const std::string xml_file);
00091     virtual ~XMLParser()
00092     {
00093       #ifdef DEBUG
00094         std::cout << "XMLParser: Destructor" << std::endl;
00095       #endif
00096     }
00097 
00102     const ticpp::Iterator<ticpp::Element> getSubjectElement() const {  return(subject_);  }
00103 
00108     const ticpp::Iterator<ticpp::Element> getServerSettingsElement() const { return(server_settings_); }
00109 
00115     const ticpp::Iterator<ticpp::Element> getHardwareElement(const unsigned int n) const
00116       {  return(hardware_.at(n).second);  }
00117 
00123     const ticpp::Iterator<ticpp::Element> getHardwareElement(const std::string& s) const
00124       {
00125         for(unsigned int n = 0; n < hardware_.size(); n++)
00126           if(s == hardware_.at(n).first)
00127             return(hardware_[n].second);
00128 
00129         return(0);
00130         //     throw(ticpp::Exception("XMLParser::getHardwareElement -- Element "+s+" not found!"));
00131         // * @throws ticpp::exception if hardware element not found.
00132       }
00133 
00139     const std::string getHardwareElementName(const unsigned int n) const {  return(hardware_.at(n).first);  }
00140 
00141 //    /**
00142 //    * @brief Get the mode of the n-th  <hardware> node.
00143 //    * @param[in] n  Number of the respective hardware block in the xml config file.
00144 //    * @return string  Type (master or slave) of the respective <hardware>
00145 //    */
00146 //    const std::string getHardwareElementType(const unsigned int n) const
00147 //    {
00148 //      return(hardware_.at(n).second->FirstChildElement(cst_.hw_mode ,false)->GetText());
00149 //    }
00150 
00155     unsigned int getNrOfHardwareElements() const  {  return(hardware_.size());  }
00156 
00162     std::map<std::string,std::string> parseSubject();
00163 
00169     std::map<std::string,std::string> parseServerSettings();
00170 
00171 //    /**
00172 //    * @brief Parse the <measurement_channels> section in the config file -- used for common channel settings.
00173 //    * @param[in] elem   The ticpp-element to parse.
00174 //    * @param[out] nr_ch The number of channels defined in the ticpp-element.
00175 //    * @param[out] naming The channel-naming defined in the ticpp-element.
00176 //    * @param[out] type The channel-types defined in the ticpp-element.
00177 //    * @throw ticpp::Exception
00178 //    */
00179 //    void parseDeviceChannels(ticpp::Iterator<ticpp::Element>const &elem, boost::uint16_t& nr_ch,
00180 //                             std::string& naming, std::string& type);
00181 //
00182 //    /**
00183 //    * @brief Parse the <selection> section in the config file -- used for individual channel settings.
00184 //    * @param[in] elem   The ticpp-element to parse.
00185 //    * @param[out] ch The channel number defined in the ticpp-element.
00186 //    * @param[out] name The channel's name defined in the ticpp-element.
00187 //    * @param[out] type The channel's type defined in the ticpp-element.
00188 //    * @throw ticpp::Exception
00189 //    */
00190 //    void parseChannelSelection(ticpp::Iterator<ticpp::Element>const &elem, boost::uint16_t& ch,
00191 //                               std::string& name, std::string& type);
00192 //
00193 //    /**
00194 //    * @brief Check if all mandatory tags in <hardware> are given.
00195 //    * @throw ticpp::Exception
00196 //    */
00197 //    void checkMandatoryHardwareTags(ticpp::Iterator<ticpp::Element> hw);
00198 
00202 //    void parseFileReader();
00203 
00207     bool usesDataFile()
00208     { return(external_data_file_); }
00209 
00210 //    /**
00211 //    * @brief TODO
00212 //    */
00213 //    const std::map<std::string, std::string> getFileReaderMap()
00214 //    { return(file_reader_map_); }
00215 
00216 
00217 //-----------------------------------------------
00218 
00219   private:
00224     void checkHardwareAttributes(std::map<std::string,std::string>& m);
00229     bool isNumber(const std::string& s)
00230     {
00231       for (unsigned int i = 0; i < s.length(); i++)
00232         if (!isdigit(s[i]))
00233           return false;
00234 
00235       return true;
00236     }
00237 
00238     bool equalsYesOrNo(const std::string& s);
00239 
00243     void parseFileLocation(ticpp::Iterator<ticpp::Element> elem, std::map<std::string, std::string>& m);
00244 
00245 //-----------------------------------------------
00246   private:
00247     ticpp::Document doc_;    
00248     ticpp::Iterator<ticpp::Element> subject_;    
00249     ticpp::Iterator<ticpp::Element> server_settings_;  
00250 
00251     ticpp::Iterator<ticpp::Element> file_reader_;  
00252     bool external_data_file_;
00253 
00254     std::map<std::string, std::string> subject_map_;
00255     std::map<std::string, std::string> server_settings_map_;
00256 //    std::map<std::string, std::string> file_reader_map_;
00257 
00261     std::vector< std::pair<std::string, ticpp::Iterator<ticpp::Element> > > hardware_;
00262 
00263     tia::Constants cst_;  
00264 };
00265 
00266 } // Namespace tobiss
00267 
00268 //---------------------------------------------------------------------------------------
00269 #endif // XMLPARSER_H
 All Data Structures Files Functions Variables