FileName

Files CCore/inc/FileName.h CCore/src/FileName.cpp

FileName is a class, developed to deal with file names as required in standard handling of the directive include. It can be used with DDL Engine.


class FileName : NoCopy
 {
   ....

  public: 
   
   // constructors
  
   FileName() noexcept;
   
   FileName(NothingType);
  
   explicit FileName(StrLen file_name);
  
   FileName(StrLen path,StrLen file_name);
   
   ~FileName();
   
   // std move

   FileName(FileName &&obj) noexcept;

   FileName & operator = (FileName &&obj) noexcept;

   // methods
   
   bool operator + () const { return ok; }
   
   bool operator ! () const { return !ok; }
  
   StrLen getStr() const;
  
   StrLen getPath() const;
   
   StrLen getFile() const;
   
   template <class P>
   void printPos(P &out,TextPos pos) { Putobj(out,getFile(),pos); }
  
   // swap/move objects
  
   void objSwap(FileName &obj);
   
   explicit FileName(ToMoveCtor<FileName> obj);
 };

A FileName object contains inside a normalized full file name. If the object is in the null state, it contains empty string and useless.

Below are some definitions.

extname — non-empty file name, without '/', '\', ':' characters, may be special ( “.”, “..” ).

name — a regular file name.

General file name:


	(dev:)opt(/)opt(extname/)*name

Normalized file name:


	(dev:)opt(/)opt(name/)*name
	(dev:)opt(../)1..(name/)*name

Absolute names:


	(dev:)opt/(name/)*name
	dev:(name/)*name

Relative names:


	(name/)*name

Default constructor and Nothing-constructor create the null object.

operator + () returns true, if the object is not null.

operator ! () returns true, if the object is null.

getStr() returns the full path.

getPath() returns a path part, including trailing slash, if any.

getFile() returns a file name part.

For example, if the full name is "c:/dir/file_name.ext", then getPath() returns "c:/dir/" and getFile() returns "file_name.ext".

printPos() is a helper method, it prints the file name followed by the given text position.

FileName is swappable and movable.

FileName is std movable. The original object is nullified during the move.

The main job this class is doing inside two non-trivial constructors. The first of them


   explicit FileName(StrLen file_name);

converts the given general file name into the normalized form. If the given name is bad the null object is created. Exception may be thrown if there is no enough memory.

The second


   FileName(StrLen path,StrLen file_name);

prepares the normalized file name from the given path and the given general file name. If the given file name is absolute, it is normalized, but if it is relative, the given path is used to generate the full path. Again, if the given name is bad the null object is created. Exception may be thrown if there is no enough memory. path is expected to be the proper path part, like getPath() return value.