OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
WPathHelper.cpp
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #include <string>
26 #include <vector>
27 #include <cstdlib>
28 
29 #include <boost/tokenizer.hpp>
30 
31 #include "WPathHelper.h"
32 
33 // path helper instance as singleton
34 boost::shared_ptr< WPathHelper > WPathHelper::m_instance = boost::shared_ptr< WPathHelper >();
35 
37 {
38  // initialize members
39 }
40 
42 {
43  // cleanup
44 }
45 
46 boost::shared_ptr< WPathHelper > WPathHelper::getPathHelper()
47 {
48  if( !m_instance )
49  {
50  m_instance = boost::shared_ptr< WPathHelper >( new WPathHelper() );
51  }
52 
53  return m_instance;
54 }
55 
56 void WPathHelper::setAppPath( boost::filesystem::path appPath )
57 {
58  m_appPath = appPath;
59  m_sharePath = m_appPath / "../share/openwalnut";
60  m_docPath = m_appPath / "../share/doc";
61  m_configPath = m_appPath / "../share/openwalnut";
62  m_libPath = m_appPath / "../lib";
63  m_modulePath = m_libPath / "openwalnut";
64 }
65 
66 boost::filesystem::path WPathHelper::getAppPath()
67 {
68  return getPathHelper()->m_appPath;
69 }
70 
71 boost::filesystem::path WPathHelper::getFontPath()
72 {
73  return getPathHelper()->m_sharePath / "fonts";
74 }
75 
76 boost::filesystem::path WPathHelper::getShaderPath()
77 {
78  return getPathHelper()->m_sharePath / "shaders";
79 }
80 
82 {
83  Fonts fonts;
84  fonts.Regular = getFontPath() / "Regular.ttf";
85  fonts.Bold = getFontPath() / "Bold.ttf";
86  fonts.Italic = getFontPath() / "Italic.ttf";
87  fonts.Default = fonts.Bold;
88 
89  return fonts;
90 }
91 
92 boost::filesystem::path WPathHelper::getModulePath()
93 {
94  return getPathHelper()->m_modulePath;
95 }
96 
97 boost::filesystem::path WPathHelper::getLibPath()
98 {
99  return getPathHelper()->m_libPath;
100 }
101 
102 boost::filesystem::path WPathHelper::getSharePath()
103 {
104  return getPathHelper()->m_sharePath;
105 }
106 
107 boost::filesystem::path WPathHelper::getDocPath()
108 {
109  return getPathHelper()->m_docPath;
110 }
111 
112 boost::filesystem::path WPathHelper::getConfigPath()
113 {
114  return getPathHelper()->m_configPath;
115 }
116 
117 std::vector< boost::filesystem::path > WPathHelper::getAllModulePaths()
118 {
119  // the list of paths
120  std::vector< boost::filesystem::path > paths;
121  // the first element always is the global search path
122  paths.push_back( getModulePath() );
123 
124  // the environment variable stores the additional paths
125  std::string additionalPaths( getenv( "OW_MODULE_PATH" ) ? getenv( "OW_MODULE_PATH" ) : "" );
126 
127  // separate list of additional paths:
128  typedef boost::tokenizer< boost::char_separator< char > > tokenizer;
129  boost::char_separator< char > sep( ";" );
130  tokenizer tok( additionalPaths, sep );
131  for( tokenizer::iterator it = tok.begin(); it != tok.end(); ++it )
132  {
133  paths.push_back( boost::filesystem::path( *it ) );
134  }
135 
136  return paths;
137 }
138