ndir.cpp

00001 // LICENSE: (Please see the file COPYING for details)
00002 //
00003 // NUS - Nemesis Utilities System: A C++ application development framework 
00004 // Copyright (C) 2006, 2008 Otavio Rodolfo Piske
00005 //
00006 //  This file is part of NUS
00007 //
00008 //  This library is free software; you can redistribute it and/or
00009 //  modify it under the terms of the GNU Lesser General Public
00010 //  License as published by the Free Software Foundation version 2.1
00011 //  of the License.
00012 //
00013 //  This library is distributed in the hope that it will be useful,
00014 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 //  Lesser General Public License for more details.
00017 //
00018 //  You should have received a copy of the GNU Lesser General Public
00019 //  License along with this library; if not, write to the Free Software
00020 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00021 //
00022 #include "ndir.h"
00023 
00024 NDir::NDir(const NString &name)
00025       : NObject(),
00026       m_contents(), 
00027       m_dir_name(name),
00028       m_dir_handle(NULL)
00029 {
00030       struct dirent *ent;
00031 
00032       m_dir_handle = opendir(m_dir_name.toChar());
00033       if (!m_dir_handle) {
00034             throw NIOException(nerror(errno), m_dir_name, 
00035                          NException::BASEIO,
00036                          NIOException::FILE,
00037                          errno);  
00038       }
00039 
00040       ent = readdir(m_dir_handle);
00041       if (!ent) {
00042             if (errno != 0) {
00043                   throw NIOException(nerror(errno), m_dir_name, 
00044                          NException::BASEIO,
00045                          NIOException::FILE,
00046                          errno);  
00047             }
00048       }
00049       
00050       loadContents(ent);
00051 }
00052 
00053 NDir::~NDir(void) { 
00054       closedir(m_dir_handle);
00055 }
00056 
00057 
00058 void NDir::loadContents(struct dirent *ent) {
00059       NString tmp_name;
00060 
00061       while (ent) {
00062             NDebug::print() << "Entry name = " << ent->d_name;
00063             
00064             tmp_name = ent->d_name;
00065             m_contents.append(tmp_name);
00066             
00067             
00068             seekdir(m_dir_handle, ent->d_off);
00069             ent = readdir(m_dir_handle);
00070             if (!ent) {
00071                   if (errno != 0) {
00072                         throw NIOException(nerror(errno), m_dir_name, 
00073                               NException::BASEIO,
00074                               NIOException::FILE,
00075                               errno);  
00076                   }
00077             }
00078       }
00079 
00080       NDebug::print() << "Added " << m_contents.size() << " entries";
00081 }
00082 
00083 NList<NString> NDir::getContents(void) const {
00084       return m_contents;
00085 }
00086 
00087 
00088 NString NDir::getName(void) const {
00089       return m_dir_name;
00090 }

Generated on Wed Mar 5 23:10:35 2008 for NemesisUtilitiesSystem by  doxygen 1.5.4