Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
clop.C
Go to the documentation of this file.
1 /* *******************************************************************
2  * Rocstar Simulation Suite *
3  * Copyright@2015, Illinois Rocstar LLC. All rights reserved. *
4  * *
5  * Illinois Rocstar LLC *
6  * Champaign, IL *
7  * www.illinoisrocstar.com *
8  * sales@illinoisrocstar.com *
9  * *
10  * License: See LICENSE file in top level of distribution package or *
11  * http://opensource.org/licenses/NCSA *
12  *********************************************************************/
13 /* *******************************************************************
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
16  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
17  * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR *
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
20  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
21  * USE OR OTHER DEALINGS WITH THE SOFTWARE. *
22  *********************************************************************/
23 #include <iostream>
24 #ifndef list
25 #include <list>
26 #endif
27 #ifndef vector
28 #include <vector>
29 #endif
30 #ifndef string
31 #include <string>
32 #endif
33 
34 using namespace std;
35 
36 #include "clop.H"
37 
38 list<clop> cloption_list;
39 
40 const string
41 stripdir(const string &pname)
42 {
43  string retval;
44  string::size_type x = pname.find("/");
45  if(x == string::npos)
46  return(pname);
47  return(pname.substr(pname.find_last_of("/")+1));
48 }
49 
50 // Adds a command line option to the list of possibilities
51 void
52 AddOp(const string &lo,const char &so)
53 {
54  cloption_list.push_back(clop(lo,so));
55 }
56 
57 // Checks to see if the command line options are
58 // correct - if there are any bad options, it reports
59 // the first one encountered
60 bool
61 CheckOps(const vector<string> &args,string &badop)
62 {
63  vector<string>::const_iterator ai = args.begin();
64  ai++;
65  while(ai != args.end()){
66  string option_string;
67  bool found = false;
68  bool longo = false;
69  if((*ai)[0] == '-'){
70  if((*ai)[1] == '-'){
71  longo = true;
72  option_string = (*ai).substr(2);
73  }
74  list<clop>::const_iterator oi = cloption_list.begin();
75  while(oi != cloption_list.end() && !found){
76  if(longo){
77  if(oi->longop() == option_string)
78  found = true;
79  }
80  else
81  if((*ai)[1] == oi->shortop())
82  found = true;
83  oi++;
84  }
85  if(!found){
86  badop = *ai;
87  return(false);
88  }
89  }
90  ai++;
91  }
92  return(true);
93 }
94 
95 // Checks to see if a boolean option is set, returns true if so
96 bool
97 GetOp(const string &ops,const vector<string> &args)
98 {
99  list<clop>::const_iterator oi = cloption_list.begin();
100  bool found = false;
101  while(oi != cloption_list.end() && !found){
102  if(*oi == ops)
103  found = true;
104  else
105  oi++;
106  }
107  if(!found)
108  return(false);
109  vector<string>::const_iterator ai = args.begin();
110  while(ai != args.end()){
111  if((*ai)[0] == '-'){
112  if((*ai)[1] != '-'){
113  if((*ai)[1] == oi->shortop()){
114  return true;
115  }
116  }
117  else if((*ai)[1] == '-'){
118  string op((*ai).substr(2));
119  if(op == oi->longop()){
120  return true;
121  }
122  }
123  }
124  ai++;
125  }
126  return false;
127 }
128 
129 // Checks to see if an option is set, and sets the option argument
130 // if it exists
131 bool
132 GetOp(const string &ops,string &rv,const vector<string> &args)
133 {
134  rv.erase();
135  list<clop>::const_iterator oi = cloption_list.begin();
136  bool found = false;
137  while(oi != cloption_list.end() && !found){
138  if(*oi == ops)
139  found = true;
140  else
141  oi++;
142  }
143  if(!found){
144  return(false);
145  }
146  vector<string>::const_iterator ai = args.begin();
147  while(ai != args.end()){
148  if((*ai)[0] == '-'){
149  if((*ai)[1] != '-'){
150  if((*ai)[1] == oi->shortop()){
151  ai++;
152  if(ai == args.end())
153  return true;
154  else {
155  if((*ai)[0] != '-')
156  rv = *ai;
157  return true;
158  }
159  }
160  }
161  else if((*ai)[1] == '-'){
162  string op((*ai).substr(2));
163  if(op == oi->longop()){
164  ai++;
165  if(ai == args.end())
166  return true;
167  else {
168  if((*ai)[0] != '-')
169  rv = *ai;
170  return true;
171  }
172  }
173  }
174  }
175  ai++;
176  }
177  return false;
178 }
179 
180 // Utilities
181 vector<string>
182 Vectize(const char **in)
183 {
184  vector<string> retVal;
185  int i = 0;
186  while(in[i] != NULL)
187  retVal.push_back(in[i++]);
188  return retVal;
189 }
190 
191 vector<string>
192 Vectize(const char **in,int n)
193 {
194  vector<string> retVal;
195  if(n <= 0) return retVal;
196  int i = 0;
197  while((in[i] != NULL) && i < n)
198  retVal.push_back(in[i++]);
199  return retVal;
200 }
201 
202 
203 
204 
205 
206 
const string stripdir(const string &)
bool GetOp(const string &ops, const vector< string > &args)
void AddOp(const string &lo, const char &so)
*********************************************************************Illinois Open Source License ****University of Illinois NCSA **Open Source License University of Illinois All rights reserved ****Developed free of to any person **obtaining a copy of this software and associated documentation to deal with the Software without including without limitation the rights to and or **sell copies of the and to permit persons to whom the **Software is furnished to do so
Definition: roccomf90.h:20
bool CheckOps(const vector< string > &args, string &badop)
blockLoc i
Definition: read.cpp:79
void int int REAL * x
Definition: read.cpp:74
list< clop > cloption_list
Definition: clop.C:38
const NT & n
Definition: clop.H:31
vector< string > Vectize(const char **)
Definition: clop.C:182