NTRT Simulator  v1.1
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
FileHelpers.cpp
Go to the documentation of this file.
1 /*
2  * Copyright © 2012, United States Government, as represented by the
3  * Administrator of the National Aeronautics and Space Administration.
4  * All rights reserved.
5  *
6  * The NASA Tensegrity Robotics Toolkit (NTRT) v1 platform is licensed
7  * under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * http://www.apache.org/licenses/LICENSE-2.0.
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
15  * either express or implied. See the License for the specific language
16  * governing permissions and limitations under the License.
17 */
18 
25 #include <string>
26 #include <fstream>
27 #include <sstream>
28 #include "FileHelpers.h"
29 #include "resources.h"
30 
31 using namespace std;
32 
33 std::string FileHelpers::getFileString(std::string fileName) {
34  std::ifstream fileInput(fileName.c_str());
35  stringstream buffer;
36  buffer << fileInput.rdbuf();
37  return buffer.str();
38 }
39 
40 std::string FileHelpers::getResourcePath(std::string relPath) {
41  stringstream buffer;
42  buffer << RESOURCE_PATH << "/" << relPath;
43  return buffer.str();
44 }
45 
46 double FileHelpers::getFinalScore(std::string filePath)
47 {
48  ifstream results;
49  results.open(filePath.c_str(), ios::in);
50 
51  std::string line;
52  // Return the last non-empty line
53  while (results >> std::ws && getline (results,line));;
54 
55  std::stringstream stream(line);
56 
57  double dist;
58 
59  // Get the first double from that line
60  stream >> dist;
61 
62  results.close();
63 
64  return dist;
65 }
static double getFinalScore(std::string filePath)
Definition: FileHelpers.cpp:46
A series of functions to assist with file input/output.