DDS  ver. 3.4
FindCfgFile.h
Go to the documentation of this file.
1 // Copyright 2014 GSI, Inc. All rights reserved.
2 //
3 // The FindCfgFile.h header holds the CFindCfgFile class.
4 //
5 #ifndef FINDCFGFILE_H_
6 #define FINDCFGFILE_H_
7 
8 // STD
9 #include <iterator>
10 // MiscCommon
11 #include "SysHelper.h"
12 
13 namespace MiscCommon
14 {
20  template <class _T>
21  struct SFileExists
22  {
23  bool operator()(const _T& _Path) const
24  {
25  _T path(_Path);
27  return (file_exists(path));
28  }
29  };
56  template <class _T>
58  {
59  public:
61  typedef std::vector<_T> container_type;
62 
63  public:
65  {
66  m_Paths.push_back(_Path);
67  return *this;
68  }
69 
71  {
72  m_Paths.push_back(_Path);
73  return *this;
74  }
75 
76  void GetCfg(_T* _RetVal)
77  {
78  if (!_RetVal)
79  return;
80  typename container_type::const_iterator iter(
81  find_if(m_Paths.begin(), m_Paths.end(), SFileExists<container_value>()));
82 
83  if (m_Paths.end() == iter)
84  return;
85 
86  *_RetVal = *iter;
87  }
88 
89  void DumpOrder(std::ostream* _stream, const container_value& _Seporator)
90  {
91  if (!_stream)
92  return;
93 
94  std::copy(
95  m_Paths.begin(), m_Paths.end(), std::ostream_iterator<container_value>(*_stream, _Seporator.c_str()));
96  }
97 
98  private:
99  container_type m_Paths;
100  };
101 }; // namespace MiscCommon
102 
103 #endif /*FINDCFGFILE_H_*/
CFindCfgFile & SetOrder(const container_value &_Path)
Definition: FindCfgFile.h:64
bool file_exists(const std::string &_FileName)
Definition: SysHelper.h:345
void GetCfg(_T *_RetVal)
Definition: FindCfgFile.h:76
#define _T(s)
Use TCHAR instead of char or wchar_t. It will be appropriately translated.
Definition: def.h:85
bool operator()(const _T &_Path) const
Definition: FindCfgFile.h:23
std::vector< _T > container_type
Definition: FindCfgFile.h:61
_T container_value
Definition: FindCfgFile.h:60
The SFileExists functor helps to check whether the file by a given full path exists or not.
Definition: FindCfgFile.h:21
void smart_path(_T *_Path)
The function extends any environment variable found in the give path to its value.
Definition: SysHelper.h:95
This class helps to find a cfg location with the best match from the given order.
Definition: FindCfgFile.h:57
CFindCfgFile & operator()(const container_value &_Path)
Definition: FindCfgFile.h:70
Miscellaneous functions and helpers are located here.
Definition: BOOST_FILESYSTEM.h:21
void DumpOrder(std::ostream *_stream, const container_value &_Seporator)
Definition: FindCfgFile.h:89