coan  6.0.1
A C/C++ Configuration Analyzer
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
argument_list.h
Go to the documentation of this file.
1 #ifndef ARGUMENT_LIST_H
2 #define ARGUMENT_LIST_H
3 #pragma once
4 /***************************************************************************
5  * Copyright (C) 2007-2013 Mike Kinghan, imk@burroingroingjoing.com *
6  * All rights reserved. *
7  * *
8  * Redistribution and use in source and binary forms, with or without *
9  * modification, are permitted provided that the following conditions *
10  * are met: *
11  * *
12  * Redistributions of source code must retain the above copyright *
13  * notice, this list of conditions and the following disclaimer. *
14  * *
15  * Redistributions in binary form must reproduce the above copyright *
16  * notice, this list of conditions and the following disclaimer in the *
17  * documentation and/or other materials provided with the distribution. *
18  * *
19  * Neither the name of Mike Kinghan nor the names of its contributors *
20  * may be used to endorse or promote products derived from this software *
21  * without specific prior written permission. *
22  * *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, *
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, *
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS *
30  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED *
31  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,*
32  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF *
33  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
34  * DAMAGE. *
35  * *
36  **************************************************************************/
37 #include "parameter_list_base.h"
38 
51 
54 
56  explicit argument_list(parameter_list_base const & parms)
57  : base(parms){}
58 
66  explicit argument_list(size_t n = 0)
67  : base(n){}
68 
76  template<class CharSeq>
77  explicit argument_list(chewer<CharSeq> & chew) {
78  read(chew);
79  }
80 
82  bool operator==(argument_list const & other) const {
83  return parameter_list_base::operator==(other) &&
84  (_expand_flags == other._expand_flags ||
85  *_expand_flags == *other._expand_flags);
86  }
87 
89  bool operator!=(argument_list const & other) const {
90  return !(*this == other);
91  }
92 
100  template<class CharSeq>
101  void read(chewer<CharSeq> & chew);
102 
103 
112  bool set_expandable(size_t n, bool expandable = false) {
113  if (_expand_flags && n < _expand_flags->size()) {
114  (*_expand_flags)[n] = expandable;
115  return true;
116  }
117  return false;
118  }
119 
127  bool is_expandable(size_t n) const {
128  return _expand_flags && n < _expand_flags->size() ?
129  (*_expand_flags)[n] : false;
130  }
131 
132 private:
133 
134  using parameter_list_base::none;
135  using parameter_list_base::empty_param;
136  using parameter_list_base::unclosed;
137 
145  static bool is_valid_char(char ch) {
146  return ch && ch != ',' && ch != '(' && ch != ')';
147  }
148 
152  std::shared_ptr<std::vector<bool>> _expand_flags;
153 
160  bool append(std::string const & arg);
161 };
162 
163 #endif //EOF
size_t size() const
Get the number of parameters in the parameter_list_base
bool operator==(argument_list const &other) const
Equality.
Definition: argument_list.h:82
static bool is_valid_char(char ch)
Say whether a character can validly appear in a member of an argument list.
template struct innards::parameter_list_base<Tag> generically defines a common interface of types rep...
argument_list(parameter_list_base const &parms)
Explicitly construct from an innards::parameter_list_base
Definition: argument_list.h:56
Class argument_list encapsulates a list of macro arguments, i.e. the arguments to a macro reference...
Definition: argument_list.h:50
bool is_expandable(size_t n) const
Say whether the nth argument, if any, is eligible for macro expansion.
parameter_list_base(size_t n=0)
Constructor for n parameters.
argument_list(chewer< CharSeq > &chew)
Explicitly construct from a chewer<CharSeq>
Definition: argument_list.h:77
bool operator!=(argument_list const &other) const
Inequality.
Definition: argument_list.h:89
std::shared_ptr< std::vector< bool > > _expand_flags
void read(chewer< CharSeq > &chew)
Read the argument_list from a chewer<CharSeq>
argument_list(size_t n=0)
Construct for n arguments.
Definition: argument_list.h:66
`template struct chewer<CharSeq> is a cursor-like type that is associated with a character-sequence t...
Definition: chew.h:248
bool set_expandable(size_t n, bool expandable=false)
Set the nth expand-flag to indicate whether the nth argument, if any, is eligible for macro expansion...
bool append(std::string const &arg)
Append an argument to the argument list.