2009-08-24 02:12:27 -07:00
|
|
|
// Copyright (C) 2002-2009 Nikolaus Gebhardt
|
|
|
|
// This file is part of the "Irrlicht Engine" and the "irrXML" project.
|
|
|
|
// For conditions of distribution and use, see copyright notice in irrlicht.h
|
|
|
|
|
|
|
|
#ifndef __IRR_PATH_H_INCLUDED__
|
|
|
|
#define __IRR_PATH_H_INCLUDED__
|
|
|
|
|
|
|
|
#include "irrString.h"
|
|
|
|
|
|
|
|
namespace irr
|
|
|
|
{
|
|
|
|
namespace io
|
|
|
|
{
|
|
|
|
|
2009-11-02 02:27:15 -08:00
|
|
|
//! Type used for all file system related strings.
|
|
|
|
/** This type will transparently handle different file system encodings. */
|
2009-08-24 02:12:27 -07:00
|
|
|
typedef core::string<fschar_t> path;
|
|
|
|
|
2009-12-05 20:52:15 -08:00
|
|
|
//! Used in places where we identify objects by a filename, but don't actually work with the real filename
|
|
|
|
/** Irrlicht is internally not case-sensitive when it comes to names.
|
|
|
|
Also this class is a first step towards support for correctly serializing renamed objects.
|
|
|
|
*/
|
|
|
|
struct SNamedPath
|
|
|
|
{
|
|
|
|
//! Constructor
|
|
|
|
SNamedPath() {}
|
|
|
|
|
|
|
|
//! Constructor
|
2009-12-06 12:42:45 -08:00
|
|
|
SNamedPath(const path& p) : Path(p), Name( PathToName(p) )
|
2009-12-05 20:52:15 -08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Is smaller comparator
|
|
|
|
bool operator <(const SNamedPath& other) const
|
|
|
|
{
|
|
|
|
return Name < other.Name;
|
|
|
|
}
|
|
|
|
|
2009-12-06 12:42:45 -08:00
|
|
|
//! Set the path. As the name depends on the path the name will also be changed.
|
2009-12-05 20:52:15 -08:00
|
|
|
void setPath(const path& p)
|
|
|
|
{
|
|
|
|
Path = p;
|
2009-12-06 12:42:45 -08:00
|
|
|
Name = PathToName(p);
|
2009-12-05 20:52:15 -08:00
|
|
|
}
|
|
|
|
|
2009-12-06 12:42:45 -08:00
|
|
|
//! Get the path. This is the original, unprocessed string passed to SNamedPath.
|
2009-12-05 20:52:15 -08:00
|
|
|
const path& getPath() const
|
|
|
|
{
|
|
|
|
return Path;
|
|
|
|
};
|
|
|
|
|
|
|
|
//! Give the file a new name which is used for identification.
|
|
|
|
void rename(const path& name)
|
|
|
|
{
|
|
|
|
Name = name;
|
|
|
|
};
|
|
|
|
|
|
|
|
//! Has the file been given a new name?
|
|
|
|
bool isRenamed() const
|
|
|
|
{
|
2009-12-06 12:42:45 -08:00
|
|
|
// Note: memory over speed here because of the typical use-cases.
|
|
|
|
return PathToName(Path) != Name;
|
2009-12-05 20:52:15 -08:00
|
|
|
}
|
|
|
|
|
2009-12-06 12:42:45 -08:00
|
|
|
//! Get the name which is used to identify the file.
|
|
|
|
//! This string is similar to the names and filenames used before Irrlicht 1.7
|
2009-12-05 20:52:15 -08:00
|
|
|
const path& getName() const
|
|
|
|
{
|
|
|
|
return Name;
|
|
|
|
}
|
|
|
|
|
2009-12-06 12:42:45 -08:00
|
|
|
//! Returns the string which should be used in serialization.
|
2009-12-05 20:52:15 -08:00
|
|
|
const path& getSerializationName() const
|
|
|
|
{
|
|
|
|
if ( isRenamed() )
|
|
|
|
return getName();
|
|
|
|
return Path;
|
|
|
|
}
|
|
|
|
|
2009-12-06 12:42:45 -08:00
|
|
|
protected:
|
|
|
|
// convert the given path string to a name string.
|
|
|
|
path PathToName(const path& p) const
|
|
|
|
{
|
|
|
|
path name(p);
|
|
|
|
name.replace( '\\', '/' );
|
|
|
|
name.make_lower();
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2009-12-05 20:52:15 -08:00
|
|
|
private:
|
|
|
|
path Path;
|
|
|
|
path Name;
|
|
|
|
};
|
|
|
|
|
2009-08-24 02:12:27 -07:00
|
|
|
} // io
|
|
|
|
} // irr
|
|
|
|
|
|
|
|
#endif // __IRR_PATH_H_INCLUDED__
|