NTRT Simulator  Version: Master
 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 std::string FileHelpers::getTestResourcePath(std::string relPath) {
47  stringstream buffer;
48  buffer << TEST_RESOURCE_PATH << "/" << relPath;
49  return buffer.str();
50 }
51 
52 double FileHelpers::getFinalScore(std::string filePath)
53 {
54  ifstream results;
55  results.open(filePath.c_str(), ios::in);
56 
57  std::string line;
58  // Return the last non-empty line
59  while (results >> std::ws && getline (results,line));;
60 
61  std::stringstream stream(line);
62 
63  double dist;
64 
65  // Get the first double from that line
66  stream >> dist;
67 
68  results.close();
69 
70  return dist;
71 }
static std::string getTestResourcePath(std::string relPath)
Definition: FileHelpers.cpp:46
static double getFinalScore(std::string filePath)
Definition: FileHelpers.cpp:52
A series of functions to assist with file input/output.
static std::string getResourcePath(std::string relPath)
Definition: FileHelpers.cpp:40