coan  6.0.1
A C/C++ Configuration Analyzer
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
parameter_list_base.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2007-2013 Mike Kinghan, imk@burroingroingjoing.com *
3  * All rights reserved. *
4  * *
5  * Redistribution and use in source and binary forms, with or without *
6  * modification, are permitted provided that the following conditions *
7  * are met: *
8  * *
9  * Redistributions of source code must retain the above copyright *
10  * notice, this list of conditions and the following disclaimer. *
11  * *
12  * Redistributions in binary form must reproduce the above copyright *
13  * notice, this list of conditions and the following disclaimer in the *
14  * documentation and/or other materials provided with the distribution. *
15  * *
16  * Neither the name of Mike Kinghan nor the names of its contributors *
17  * may be used to endorse or promote products derived from this software *
18  * without specific prior written permission. *
19  * *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
24  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, *
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, *
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS *
27  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED *
28  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,*
29  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF *
30  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
31  * DAMAGE. *
32  * *
33  **************************************************************************/
34 #include "parameter_list_base.h"
35 #include <algorithm>
36 #include <cassert>
37 
42 using namespace std;
43 using namespace innards;
44 
45 parameter_list_base::parameter_list_base(size_t n)
46 : _params(n ? new vector<string>(n) : nullptr),
47  _defect(none),_variadic(false)
48 {
49  if (_params) {
50  for (unsigned i = 0; i < size(); ++i) {
51  (*_params)[i] = string("$") + to_string(i + 1);
52  }
53  }
54 }
55 
57 {
58  string list;
59  if (_params) {
60  list.append(1,'(');
61  auto start = _params->begin();
62  auto const end = _params->end();
63  for ( ; start < end - 1; ++start) {
64  list.append(*start);
65  list.append(1,',');
66  }
67  list.append(*start);
68  if (_defect != unclosed) {
69  list.append(1,')');
70  }
71  }
72  return list;
73 }
74 
75 size_t parameter_list_base::which(std::string const & str) const
76 {
77  if (!_params) {
78  return -1;
79  }
80  auto where = find(_params->begin(),_params->end(),str);
81  return where == _params->end() ? string::npos : where - _params->begin();
82 }
83 
84 // EOF
std::string str() const
Cast the parameter list to its canonical string representation.
size_t size() const
Get the number of parameters in the parameter_list_base
std::vector< std::string >::iterator end()
Get a [const] iterator to the end of the parameter list.
std::shared_ptr< std::vector< std::string > > _params
The list of parameters.
defect _defect
Is the parameter_list_base well-formed?
size_t which(std::string const &str) const
Get the index of the parameter that matches a string, if any, else -1.
No severity.