MessageTypeParser.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (C) 2014 by Ralf Kaestner *
3  * ralf.kaestner@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the Lesser GNU General Public License as published by*
7  * the Free Software Foundation; either version 3 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * Lesser GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the Lesser GNU General Public License *
16  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17  ******************************************************************************/
18 
20 
21 namespace variant_topic_tools {
22 
23 /*****************************************************************************/
24 /* Static initializers */
25 /*****************************************************************************/
26 
27 const boost::regex MessageTypeParser::packageExpression =
28  boost::regex("[a-zA-Z][a-zA-Z0-9_]*");
29 
30 const boost::regex MessageTypeParser::typeExpression =
31  boost::regex("[a-zA-Z][a-zA-Z0-9_]*");
32 
33 const boost::regex MessageTypeParser::plainTypeExpression =
34  boost::regex("("+typeExpression.str()+")");
35 
37  boost::regex("("+packageExpression.str()+")/("+typeExpression.str()+")");
38 
39 /*****************************************************************************/
40 /* Constructors and Destructor */
41 /*****************************************************************************/
42 
44 }
45 
47 }
48 
49 /*****************************************************************************/
50 /* Methods */
51 /*****************************************************************************/
52 
53 bool MessageTypeParser::matchType(const std::string& expression, std::string&
54  package, std::string& type) {
55  boost::smatch match;
56 
57  if (boost::regex_match(expression, match, packageTypeExpression)) {
58  package = std::string(match[1].first, match[1].second);
59  type = std::string(match[2].first, match[2].second);
60 
61  return true;
62  }
63  else if (boost::regex_match(expression, match, plainTypeExpression)) {
64  package = std::string();
65  type = std::string(match[1].first, match[1].second);
66 
67  return true;
68  }
69  else
70  return false;
71 }
72 
73 }
static const boost::regex plainTypeExpression
Regular expression for matching a message type without package prefix.
static const boost::regex packageTypeExpression
Regular expression for matching a message type with package prefix.
static const boost::regex packageExpression
Regular expression for matching a package.
static bool matchType(const std::string &expression, std::string &package, std::string &type)
Match any message type expression.
Header file providing the MessageTypeParser class interface.
static const boost::regex typeExpression
Regular expression for matching a message type.


variant_topic_tools
Author(s): Ralf Kaestner
autogenerated on Sat Jan 9 2021 03:56:49