Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7610 in orxonox.OLD for branches/qt_gui/src/lib


Ignore:
Timestamp:
May 12, 2006, 11:49:48 AM (19 years ago)
Author:
bensch
Message:

orxonox/qt_gui: directory splitted into declaration and definition

Location:
branches/qt_gui/src/lib
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • branches/qt_gui/src/lib/Makefile.am

    r7609 r7610  
    2525                util/preferences.cc \
    2626                util/threading.cc \
     27                util/directory.cc \
    2728                \
    2829                data/data_tank.cc
  • branches/qt_gui/src/lib/shell/shell_completion_plugin.cc

    r7609 r7610  
    9494  void CompletorFileSystem::addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const
    9595  {
    96     OS::Directory dir;
     96    Directory dir;
    9797
    9898    if (completionBegin.empty()) // if we do not yet have the beginning of the line, start with the chosen startDir.
  • branches/qt_gui/src/lib/util/directory.h

    r7609 r7610  
    1717 */
    1818
    19 #ifndef OSLINK_OSDIR_HEADER_H_
    20 #define OSLINK_OSDIR_HEADER_H_
     19#ifndef __DIRECTORY_H_
     20#define __DIRECTORY_H_
    2121
    2222#if defined(unix) || defined(__unix) || defined(__unix__)
     
    3131
    3232#if defined(OSLINK_OSDIR_NOTSUPPORTED)
    33 
    34 namespace OS
    35 {
    36   class Directory
    37   {
    38     public:
    39       Directory(const std::string&) { }
    40       bool open(const std::string&) {};
    41       void close() {};
    42 
    43       operator void*() const { return (void*)0; }
    44       std::string next() { return ""; }
    45   };
    46 }
     33#warning DIRECTORY NOT SUPPORTET
    4734
    4835#elif defined(OSLINK_OSDIR_POSIX)
    49 
    5036#include <sys/types.h>
    5137#include <dirent.h>
    5238
    53 namespace OS
    54 {
    55   class Directory
    56   {
    57     public:
    58       Directory(const std::string& directoryName = "")
    59           : willfail(false)
    60       {
    61         this->handle = NULL;
    62         this->willfail = true;
    63         this->open(directoryName);
    64       }
    65 
    66       ~Directory()
    67       {
    68         this->close();
    69       }
    70 
    71       bool open(const std::string& directoryName)
    72       {
    73         if (this->handle != NULL)
    74           this->close();
    75         this->handle = opendir(directoryName.c_str());
    76         if (!handle)
    77           willfail = true;
    78         else
    79         {
    80           willfail = false;
    81           dirent* entry = readdir(handle);
    82           if (entry)
    83             current = entry->d_name;
    84           else
    85             willfail = true;
    86         }
    87       }
    88 
    89       void close()
    90       {
    91         if (this->handle != NULL)
    92           closedir(handle);
    93         this->handle = NULL;
    94         this->willfail = true;
    95         this->current = "";
    96       }
    97 
    98       operator void*() const
    99       {
    100         return willfail ? (void*)0:(void*)(-1);
    101       }
    102 
    103       std::string next()
    104       {
    105         std::string prev(current);
    106         dirent* entry = readdir(handle);
    107         if (entry)
    108           current = entry->d_name;
    109         else
    110           willfail = true;
    111         return prev;
    112       }
    113 
    114     private:
    115       DIR* handle;
    116       bool willfail;
    117       std::string current;
    118   };
    119 }
    120 
    12139#elif defined(OSLINK_OSDIR_WINDOWS)
    12240
     41/// HACK
    12342#ifdef DATADIR
    12443#undef DATADIR
     
    12847#include <winbase.h>
    12948
    130 namespace OS
     49#endif
     50
     51class Directory
    13152{
    132   class Directory
    133   {
    134     public:
    135       Directory(const std::string& directoryName = "")
    136           : handle(INVALID_HANDLE_VALUE), willfail(true)
    137       {
    138         this->open(directoryName);
    139       }
     53public:
     54  Directory(const std::string& directoryName = "");
     55  ~Directory();
    14056
    141       ~Directory()
    142       {
    143         this->close();
    144       }
     57  bool open(const std::string& directoryName);
     58  void close();
     59  operator void*() const { return willfail ? (void*)0:(void*)(-1); }
    14560
    146       bool open(const std::string& directoryName)
    147       {
    148         if (handle != INVALID_HANDLE_VALUE)
    149           this->close();
     61  std::string next();
    15062
    151         // First check the attributes trying to access a non-Directory with
    152         // FindFirstFile takes ages
    153         DWORD attrs = GetFileAttributes(directoryName.c_str());
    154         if ( (attrs == 0xFFFFFFFF) || ((attrs && FILE_ATTRIBUTE_DIRECTORY) == 0) )
    155         {
    156           willfail = true;
    157           return false;
    158         }
    159         std::string Full(directoryName);
    160         // Circumvent a problem in FindFirstFile with c:\\* as parameter
    161         if ( (Full.length() > 0) && (Full[Full.length()-1] != '\\') )
    162           Full += "\\";
    163         WIN32_FIND_DATA entry;
    164         handle = FindFirstFile( (Full+"*").c_str(), &entry);
    165         if (handle == INVALID_HANDLE_VALUE)
    166           {
    167             willfail = true;
    168             return false;
    169           }
    170         else
    171           {
    172             willfail = false;
    173             current = entry.cFileName;
    174             return true;
    175           }
    176       }
    177 
    178       void close()
    179       {
    180         if (handle != INVALID_HANDLE_VALUE)
    181           FindClose(handle);
    182         this->willfail = true;
    183       }
    184 
    185       operator void*() const
    186       {
    187         return willfail ? (void*)0:(void*)(-1);
    188       }
    189 
    190       std::string next()
    191       {
    192         std::string prev = current;
    193         WIN32_FIND_DATA entry;
    194         int ok = FindNextFile(handle, &entry);
    195         if (!ok)
    196           willfail = true;
    197         else
    198           current = entry.cFileName;
    199         return current;
    200       }
     63private:
     64#if defined(OSLINK_OSDIR_POSIX)
     65  DIR* handle;
     66#elif defined(OSLINK_OSDIR_WINDOWS)
     67    HANDLE    handle;
     68#endif
     69  bool willfail;
     70  std::string current;
     71};
    20172
    20273
    203     private:
    204       HANDLE    handle;
    205       bool      willfail;
    206       std::string current;
    207   };
    208 }
    20974
    210 
    211 #endif
    212 
    213 #endif
     75#endif /* __DIRECTORY_H_ */
    21476
    21577/**
Note: See TracChangeset for help on using the changeset viewer.