source: soft/giet_vm/memo/src/path_handler.cpp

Last change on this file was 163, checked in by karaoui, 12 years ago

changing mover to memo
changing soft.bin to soft.elf
...

File size: 2.0 KB
Line 
1/* -*- c++ -*-
2 *TODO
3 *
4 * SoCLib is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published
6 * by the Free Software Foundation; version 2.1 of the License.
7 *
8 * SoCLib is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with SoCLib; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 * 02110-1301 USA
17 *
18 * SOCLIB_LGPL_HEADER_END
19 *
20 * Copyright (c) UPMC, Lip6, SoC
21 *         Mohamed Lamine Karaoui <Mohamed.Karaoui@lip6.fr>, 2012
22 */
23
24#include "path_handler.h"
25   
26PathHandler::PathHandler(const std::string& filepath)
27                        :delim('/')
28{
29   dirPath = getFilePath(filepath);
30}
31   
32std::string PathHandler::getFullPath(const std::string& filepath) const
33{
34    return dirPath+filepath;
35}
36
37std::vector<std::string>& PathHandler::split(const std::string &s, char delim, std::vector<std::string> &elems)
38{
39    std::stringstream ss(s);
40    std::string item;
41    while(std::getline(ss, item, delim)) 
42    {
43        elems.push_back(item);
44    }
45    return elems;
46}
47
48
49std::vector<std::string> PathHandler::split(const std::string &s, char delim) 
50{
51    std::vector<std::string> elems;
52    return split(s, delim, elems);
53}
54
55
56std::string PathHandler::getFilePath(const std::string& filepath)
57{
58    std::string path;
59
60    std::vector<std::string> vst= split(filepath, delim);
61
62    if(vst.size() < 2)
63        return "";
64
65    for (unsigned i=0; i<(vst.size()-1); i++)
66        path+= vst.at(i);
67
68    return path+'/';
69}
70
71std::string PathHandler::getFileName(const std::string& filepath)
72{
73
74    std::vector<std::string> vst= split(filepath, delim);
75
76    return vst.back();
77}
78   
79PathHandler::~PathHandler()
80{
81}
Note: See TracBrowser for help on using the repository browser.