OpenClonk
DirectoryIterator Class Reference

#include <StdFile.h>

Public Member Functions

 DirectoryIterator (const char *dirname)
 
 DirectoryIterator ()
 
DirectoryIteratoroperator= (const DirectoryIterator &)
 
 DirectoryIterator (const DirectoryIterator &)
 
 ~DirectoryIterator ()
 
const char * operator* () const
 
const char * GetName () const
 
size_t GetFileSize () const
 
DirectoryIteratoroperator++ ()
 
DirectoryIterator operator++ (int)
 
void Clear ()
 
void Reset (const char *dirname, bool force_reread=false)
 
void Reset ()
 

Friends

struct DirectoryIteratorP
 

Detailed Description

Definition at line 85 of file StdFile.h.

Constructor & Destructor Documentation

◆ DirectoryIterator() [1/3]

DirectoryIterator::DirectoryIterator ( const char *  dirname)

Definition at line 937 of file StdFile.cpp.

References DirectoryIteratorP::directory, DirectorySeparator, DirectoryIteratorP::files, StdStrBuf::getData(), GetWideChar(), Log(), and LogF().

938  : p(new DirectoryIteratorP), iter(p->files.end())
939 {
940  Read(dirname);
941 }
DirectoryIterator::FileList files
Definition: StdFile.cpp:872
Here is the call graph for this function:

◆ DirectoryIterator() [2/3]

DirectoryIterator::DirectoryIterator ( )

Definition at line 877 of file StdFile.cpp.

878  : p(new DirectoryIteratorP), iter(p->files.end())
879 {}
DirectoryIterator::FileList files
Definition: StdFile.cpp:872

◆ DirectoryIterator() [3/3]

DirectoryIterator::DirectoryIterator ( const DirectoryIterator other)

Definition at line 880 of file StdFile.cpp.

References DirectoryIteratorP::ref.

881  : p(other.p), iter(other.iter)
882 {
883  ++p->ref;
884 }

◆ ~DirectoryIterator()

DirectoryIterator::~DirectoryIterator ( )

Definition at line 893 of file StdFile.cpp.

References DirectoryIteratorP::ref.

894 {
895  if (--p->ref == 0)
896  delete p;
897 }

Member Function Documentation

◆ Clear()

void DirectoryIterator::Clear ( )

Definition at line 899 of file StdFile.cpp.

References DirectoryIteratorP::directory, DirectoryIteratorP, DirectoryIteratorP::files, and DirectoryIteratorP::ref.

Referenced by GetName().

900 {
901  // clear cache
902  if (p->ref > 1)
903  {
904  // Detach from shared memory
905  --p->ref;
906  p = new DirectoryIteratorP;
907  }
908  p->directory.clear();
909  p->files.clear();
910  iter = p->files.end();
911 }
std::string directory
Definition: StdFile.cpp:873
friend struct DirectoryIteratorP
Definition: StdFile.h:106
DirectoryIterator::FileList files
Definition: StdFile.cpp:872
Here is the caller graph for this function:

◆ GetFileSize()

size_t DirectoryIterator::GetFileSize ( ) const

Definition at line 1035 of file StdFile.cpp.

References FileSize().

Referenced by GetName(), and C4GroupEntry::Set().

1036 {
1037 #ifdef _WIN32
1038  return iter->second;
1039 #else
1040  return FileSize(iter->first.c_str());
1041 #endif
1042 }
size_t FileSize(const char *fname)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetName()

const char* DirectoryIterator::GetName ( ) const
inline

Definition at line 96 of file StdFile.h.

References Clear(), GetFileSize(), operator++(), and Reset().

96 { return **this; }
Here is the call graph for this function:

◆ operator*()

const char * DirectoryIterator::operator* ( ) const

Definition at line 1022 of file StdFile.cpp.

References DirectoryIteratorP::files.

1023 {
1024  if (iter == p->files.end())
1025  return nullptr;
1026  return iter->first.c_str();
1027 }
DirectoryIterator::FileList files
Definition: StdFile.cpp:872

◆ operator++() [1/2]

DirectoryIterator & DirectoryIterator::operator++ ( )

Definition at line 1015 of file StdFile.cpp.

References DirectoryIteratorP::files.

Referenced by GetName().

1016 {
1017  if (iter != p->files.end())
1018  ++iter;
1019  return *this;
1020 }
DirectoryIterator::FileList files
Definition: StdFile.cpp:872
Here is the caller graph for this function:

◆ operator++() [2/2]

DirectoryIterator DirectoryIterator::operator++ ( int  )

Definition at line 1028 of file StdFile.cpp.

1029 {
1030  DirectoryIterator tmp(*this);
1031  ++*this;
1032  return tmp;
1033 }

◆ operator=()

DirectoryIterator & DirectoryIterator::operator= ( const DirectoryIterator other)

Definition at line 886 of file StdFile.cpp.

References DirectoryIteratorP::ref.

887 {
888  p = other.p; iter = other.iter;
889  ++p->ref;
890  return *this;
891 }

◆ Reset() [1/2]

void DirectoryIterator::Reset ( const char *  dirname,
bool  force_reread = false 
)

Definition at line 918 of file StdFile.cpp.

References DirectoryIteratorP::directory, DirectoryIteratorP, DirectoryIteratorP::files, and DirectoryIteratorP::ref.

Referenced by C4Group_PackDirectoryTo(), and C4Group::Merge().

919 {
920  if (p->directory == dirname && !force_reread)
921  {
922  // Skip reinitialisation and just reset the iterator
923  iter = p->files.begin();
924  return;
925  }
926  if (p->ref > 1)
927  {
928  // Detach from shared memory
929  --p->ref;
930  p = new DirectoryIteratorP;
931  }
932  p->files.clear();
933  iter = p->files.end();
934  Read(dirname);
935 }
std::string directory
Definition: StdFile.cpp:873
friend struct DirectoryIteratorP
Definition: StdFile.h:106
DirectoryIterator::FileList files
Definition: StdFile.cpp:872
Here is the caller graph for this function:

◆ Reset() [2/2]

void DirectoryIterator::Reset ( )

Definition at line 913 of file StdFile.cpp.

References DirectoryIteratorP::files.

Referenced by GetName().

914 {
915  iter = p->files.begin();
916 }
DirectoryIterator::FileList files
Definition: StdFile.cpp:872
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ DirectoryIteratorP

friend struct DirectoryIteratorP
friend

Definition at line 106 of file StdFile.h.

Referenced by Clear(), and Reset().


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