GraphLab: Distributed Graph-Parallel API  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
options_map.cpp
1 /**
2  * Copyright (c) 2009 Carnegie Mellon University.
3  * All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing,
12  * software distributed under the License is distributed on an "AS
13  * IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14  * express or implied. See the License for the specific language
15  * governing permissions and limitations under the License.
16  *
17  * For more about this software visit:
18  *
19  * http://www.graphlab.ml.cmu.edu
20  *
21  */
22 
23 
24 /**
25  * Also contains code that is Copyright 2011 Yahoo! Inc. All rights
26  * reserved.
27  *
28  * Contributed under the iCLA for:
29  * Joseph Gonzalez ([email protected])
30  *
31  */
32 
33 
34 #include <string>
35 #include <sstream>
36 #include <iostream>
37 #include <iomanip>
38 
39 #include <graphlab/options/options_map.hpp>
40 
41 namespace graphlab {
42 
43 
44  void options_map::parse_string(std::string arguments) {
45  std::pair<std::string, options_map> ret;
46  // Break the string appart
47  if(!arguments.empty()) {
48  std::replace(arguments.begin(), arguments.end(), ',', ' ');
49  std::replace(arguments.begin(), arguments.end(), ';', ' ');
50  std::stringstream arg_strm(arguments);
51  bool ret = parse_options(arg_strm);
52  if (ret == false) {
53  logstream(LOG_FATAL) << "Malformed option. Failed to parse \""
54  << arguments << "\"" << std::endl;
55  }
56  }
57  }
58 
59 
60 
61  std::ostream& operator<<(std::ostream& out,
62  const graphlab::options_map& opts) {
63  // save the format flags
64  std::ios_base::fmtflags fmt = out.flags();
65 
66  std::map<std::string,
68  i = opts.options.begin();
69  while(i != opts.options.end()) {
70  //out.setf(std::ios::left);
71  out << std::setw(18) << std::left << i->first;
72  out << std::setw(2) << "= ";
73  //out.setf(std::ios::right);
74  out << i->second.strval;
75  out << std::endl;
76  ++i;
77  }
78  // reset the format flags
79  out.flags(fmt);
80  out << std::endl;
81  return out;
82  }
83 
84 }; // end of namespace graphlab
85