OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
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::DirectoryIterator ( const char *  dirname)

Definition at line 947 of file StdFile.cpp.

948  : p(new DirectoryIteratorP), iter(p->files.end())
949 {
950  Read(dirname);
951 }
DirectoryIterator::FileList files
Definition: StdFile.cpp:882
DirectoryIterator::DirectoryIterator ( )

Definition at line 887 of file StdFile.cpp.

888  : p(new DirectoryIteratorP), iter(p->files.end())
889 {}
DirectoryIterator::FileList files
Definition: StdFile.cpp:882
DirectoryIterator::DirectoryIterator ( const DirectoryIterator other)

Definition at line 890 of file StdFile.cpp.

References DirectoryIteratorP::ref.

891  : p(other.p), iter(other.iter)
892 {
893  ++p->ref;
894 }
DirectoryIterator::~DirectoryIterator ( )

Definition at line 903 of file StdFile.cpp.

References DirectoryIteratorP::ref.

904 {
905  if (--p->ref == 0)
906  delete p;
907 }

Member Function Documentation

void DirectoryIterator::Clear ( )

Definition at line 909 of file StdFile.cpp.

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

910 {
911  // clear cache
912  if (p->ref > 1)
913  {
914  // Detach from shared memory
915  --p->ref;
916  p = new DirectoryIteratorP;
917  }
918  p->directory.clear();
919  p->files.clear();
920  iter = p->files.end();
921 }
std::string directory
Definition: StdFile.cpp:883
friend struct DirectoryIteratorP
Definition: StdFile.h:106
DirectoryIterator::FileList files
Definition: StdFile.cpp:882
size_t DirectoryIterator::GetFileSize ( ) const

Definition at line 1044 of file StdFile.cpp.

References FileSize().

Referenced by C4GroupEntry::Set().

1045 {
1046 #ifdef _WIN32
1047  return iter->second;
1048 #else
1049  return FileSize(iter->first.c_str());
1050 #endif
1051 }
size_t FileSize(const char *szFilename)
Definition: StdFile.cpp:448

Here is the call graph for this function:

Here is the caller graph for this function:

const char* DirectoryIterator::GetName ( ) const
inline

Definition at line 96 of file StdFile.h.

96 { return **this; }
const char * DirectoryIterator::operator* ( ) const

Definition at line 1031 of file StdFile.cpp.

References DirectoryIteratorP::files.

1032 {
1033  if (iter == p->files.end())
1034  return nullptr;
1035  return iter->first.c_str();
1036 }
DirectoryIterator::FileList files
Definition: StdFile.cpp:882
DirectoryIterator & DirectoryIterator::operator++ ( )

Definition at line 1024 of file StdFile.cpp.

References DirectoryIteratorP::files.

1025 {
1026  if (iter != p->files.end())
1027  ++iter;
1028  return *this;
1029 }
DirectoryIterator::FileList files
Definition: StdFile.cpp:882
DirectoryIterator DirectoryIterator::operator++ ( int  )

Definition at line 1037 of file StdFile.cpp.

1038 {
1039  DirectoryIterator tmp(*this);
1040  ++*this;
1041  return tmp;
1042 }
DirectoryIterator & DirectoryIterator::operator= ( const DirectoryIterator other)

Definition at line 896 of file StdFile.cpp.

References DirectoryIteratorP::ref.

897 {
898  p = other.p; iter = other.iter;
899  ++p->ref;
900  return *this;
901 }
void DirectoryIterator::Reset ( const char *  dirname,
bool  force_reread = false 
)

Definition at line 928 of file StdFile.cpp.

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

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

929 {
930  if (p->directory == dirname && !force_reread)
931  {
932  // Skip reinitialisation and just reset the iterator
933  iter = p->files.begin();
934  return;
935  }
936  if (p->ref > 1)
937  {
938  // Detach from shared memory
939  --p->ref;
940  p = new DirectoryIteratorP;
941  }
942  p->files.clear();
943  iter = p->files.end();
944  Read(dirname);
945 }
std::string directory
Definition: StdFile.cpp:883
friend struct DirectoryIteratorP
Definition: StdFile.h:106
DirectoryIterator::FileList files
Definition: StdFile.cpp:882

Here is the caller graph for this function:

void DirectoryIterator::Reset ( )

Definition at line 923 of file StdFile.cpp.

References DirectoryIteratorP::files.

924 {
925  iter = p->files.begin();
926 }
DirectoryIterator::FileList files
Definition: StdFile.cpp:882

Friends And Related Function Documentation

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: