aimsdata 6.0.0
Neuroimaging data handling
fdfutil.h
Go to the documentation of this file.
1/* This software and supporting documentation are distributed by
2 * Institut Federatif de Recherche 49
3 * CEA/NeuroSpin, Batiment 145,
4 * 91191 Gif-sur-Yvette cedex
5 * France
6 *
7 * This software is governed by the CeCILL-B license under
8 * French law and abiding by the rules of distribution of free software.
9 * You can use, modify and/or redistribute the software under the
10 * terms of the CeCILL-B license as circulated by CEA, CNRS
11 * and INRIA at the following URL "http://www.cecill.info".
12 *
13 * As a counterpart to the access to the source code and rights to copy,
14 * modify and redistribute granted by the license, users are provided only
15 * with a limited warranty and the software's author, the holder of the
16 * economic rights, and the successive licensors have only limited
17 * liability.
18 *
19 * In this respect, the user's attention is drawn to the risks associated
20 * with loading, using, modifying and/or developing or reproducing the
21 * software by the user in light of its specific status of free software,
22 * that may mean that it is complicated to manipulate, and that also
23 * therefore means that it is reserved for developers and experienced
24 * professionals having in-depth computer knowledge. Users are therefore
25 * encouraged to load and test the software's suitability as regards their
26 * requirements in conditions enabling the security of their systems and/or
27 * data to be ensured and, more generally, to use and operate it in the
28 * same conditions as regards security.
29 *
30 * The fact that you are presently reading this means that you have had
31 * knowledge of the CeCILL-B license and that you accept its terms.
32 */
33
34#ifndef AIMS_IO_FDFUTIL_H
35#define AIMS_IO_FDFUTIL_H
36
37#include <cartobase/type/string_conversion.h>
38#include <iostream>
39#include <fstream>
40#include <sstream>
41#include <vector>
42#include <iterator>
43#include <algorithm>
44
45void removeCharacters(std::string &line, std::string character);
46
47void tokenize(const std::string& str, std::vector<std::string>& tokens, const std::string& delimiters = " ");
48
49std::string parseLine(std::string line);
50
51template <class T>
52void stringToVector (std::string value, std::vector<T>& values)
53{
54 std::vector<std::string> tokens;
55
56 // value consists of something like {256,256}
57 std::string::size_type startBracketPosition = value.find_first_of("{", 0);
58 std::string::size_type endBracketPosition = value.find_first_of("}", startBracketPosition);
59
60 if ( startBracketPosition != std::string::npos && endBracketPosition != std::string::npos) {
61 std::string elements = value.substr(startBracketPosition + 1, endBracketPosition - startBracketPosition - 1);
62
63
64 tokenize(elements, tokens, ",");
65 }
66
67 T element;
68
69 for(unsigned int i=0; i<tokens.size(); i++) {
70 carto::stringTo(tokens[i], element);
71 values.push_back(element);
72 }
73}
74
75template <class T>
76void printVector (std::ostream& os, std::string name, const std::vector<T>& vect)
77{
78 int size = vect.size();
79
80 os << name << " {";
81
82 for(int i=0; i < size; i++) {
83 os << vect[i];
84
85 if (i < size - 1)
86 os << ", ";
87 }
88
89 os << "}" << std::endl;
90}
91
92#endif
void tokenize(const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters=" ")
void removeCharacters(std::string &line, std::string character)
std::string parseLine(std::string line)
void stringToVector(std::string value, std::vector< T > &values)
Definition fdfutil.h:52
void printVector(std::ostream &os, std::string name, const std::vector< T > &vect)
Definition fdfutil.h:76
void stringTo(const std::string &value, T &result)