Back to index

nux  3.0.0
Public Member Functions | Private Attributes
nux::FilePath Class Reference

#include <FilePath.h>

Collaboration diagram for nux::FilePath:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 FilePath ()
 ~FilePath ()
void AddSearchPath (const NString &searchpath)
void AddSearchPath (const std::vector< NString > &searchpath)
NString GetPathToFile (const TCHAR *filename) const
NString GetFile (const TCHAR *filename) const

Private Attributes

std::vector< NStringm_SearchPath

Detailed Description

Definition at line 44 of file FilePath.h.


Constructor & Destructor Documentation

Definition at line 30 of file FilePath.cpp.

  {
    if (std::find (m_SearchPath.begin(), m_SearchPath.end(), TEXT ("") ) != m_SearchPath.end() )
      return;

    m_SearchPath.push_back (TEXT ("") ); // for fully qualified path
  }

Here is the caller graph for this function:

Definition at line 38 of file FilePath.cpp.

  {

  }

Member Function Documentation

void nux::FilePath::AddSearchPath ( const NString searchpath)

Definition at line 43 of file FilePath.cpp.

  {
    if (std::find (m_SearchPath.begin(), m_SearchPath.end(), searchpath) != m_SearchPath.end() )
      return;

    m_SearchPath.push_back (searchpath);
  }

Here is the caller graph for this function:

void nux::FilePath::AddSearchPath ( const std::vector< NString > &  searchpath)

Definition at line 51 of file FilePath.cpp.

  {
    for (unsigned int i = 0; i < searchpath.size(); i++)
    {
      if (std::find (m_SearchPath.begin(), m_SearchPath.end(), searchpath[i]) == m_SearchPath.end() )
        m_SearchPath.push_back (searchpath[i]);
    }
  }
NString nux::FilePath::GetFile ( const TCHAR filename) const

Definition at line 79 of file FilePath.cpp.

  {
    NUX_RETURN_VALUE_IF_NULL (filename, NString (TEXT ("") ) );

    if (NString (filename) == NString (TEXT ("") ) )
      return NString (TEXT ("") );

    NString FileName = filename;

    if (GFileManager.FileExist (FileName.GetTCharPtr() ) )
      return FileName;

    for (unsigned int i = 0; i < m_SearchPath.size(); i++)
    {
      if (m_SearchPath[i].Size() == 0)
        continue;

      NString FilePath;
   
      if ((m_SearchPath[i].GetLastChar () == TEXT('/')) || (m_SearchPath[i].GetLastChar () == TEXT('\\')))
        FilePath = m_SearchPath[i] + filename;
      else
        FilePath = m_SearchPath[i] + NUX_PATH_SEPARATOR_STRING + filename;


      if (GFileManager.FileExist (FilePath.GetTCharPtr() ) )
        return FilePath;
    }

    // Still not found. Then peel off the root of the filename and append our custom search path.
    //      filename = "MediaProg/UI3DGraphics/MyFile.txt"
    //      search for:
    //            CustomPath0/UI3DGraphics/MyFile.txt
    //            CustomPath1/UI3DGraphics/MyFile.txt
    //            CustomPath2/UI3DGraphics/MyFile.txt
    //            CustomPath3/UI3DGraphics/MyFile.txt
    //            CustomPath0/MyFile.txt
    //            CustomPath1/MyFile.txt
    //            CustomPath2/MyFile.txt
    //            CustomPath3/MyFile.txt
    //

    FileName = filename;

    for (size_t i = 0; i < m_SearchPath.size(); i++)
    {
      size_t pos;
      NString PathName;

      while (FileName.FindFirstOccurenceOf (TEXT ("\\/") ) != std::string::npos)
      {
        pos = FileName.FindFirstOccurenceOf (TEXT ("\\/") ) + 1;

        FileName = FileName.GetSubString (pos, FileName.Length() - pos);

        if ((m_SearchPath[i].GetLastChar () == TEXT('/')) || (m_SearchPath[i].GetLastChar () == TEXT('\\')))
          PathName = m_SearchPath[i] + FileName;
        else
          PathName = m_SearchPath[i] + NUX_PATH_SEPARATOR_STRING + FileName;


        if (GFileManager.FileExist (PathName.GetTCharPtr() ) )
          return PathName;
      }
    }

    nuxDebugMsg (TEXT ("[FilePath::GetFile] Cannot find file: %s"), filename);
    return NString (TEXT ("") );
  }

Here is the call graph for this function:

Here is the caller graph for this function:

NString nux::FilePath::GetPathToFile ( const TCHAR filename) const

Definition at line 60 of file FilePath.cpp.

  {
    NString FileName = GetFile (filename);

    int loc = (int) FileName.FindLastOccurence (TEXT ('\\') );

    if (loc == -1)
    {
      loc = (int) FileName.FindLastOccurence (TEXT ('/') );
    }

    if (loc != -1)
      FileName = FileName.GetSubString (0, loc);
    else
      FileName = NString (TEXT (".") );

    return FileName;
  }

Here is the call graph for this function:


Member Data Documentation

std::vector<NString> nux::FilePath::m_SearchPath [private]

Definition at line 57 of file FilePath.h.


The documentation for this class was generated from the following files: