Commit 6ff4d50f authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

filesystem: File: Split common parts in a common class

parent 903410bf
......@@ -66,6 +66,7 @@ list(APPEND SRC_LIST ${HEADERS_LIST}
Settings.cpp
factory/FileSystem.cpp
filesystem/common/CommonFile.cpp
filesystem/${ARCH_FOLDER}/Directory.cpp
filesystem/${ARCH_FOLDER}/File.cpp
......
/*****************************************************************************
* Media Library
*****************************************************************************
* Copyright (C) 2015 Hugo Beauzée-Luyssen, Videolabs
*
* Authors: Hugo Beauzée-Luyssen<hugo@beauzee.fr>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "CommonFile.h"
#include "Utils.h"
namespace fs
{
CommonFile::CommonFile( const std::string& filePath )
: m_path( utils::file::directory( filePath ) )
, m_name( utils::file::fileName( filePath ) )
, m_fullPath( filePath )
, m_extension( utils::file::extension( filePath ) )
{
}
const std::string& CommonFile::name() const
{
return m_name;
}
const std::string& CommonFile::path() const
{
return m_path;
}
const std::string& CommonFile::fullPath() const
{
return m_fullPath;
}
const std::string& CommonFile::extension() const
{
return m_extension;
}
}
/*****************************************************************************
* Media Library
*****************************************************************************
* Copyright (C) 2015 Hugo Beauzée-Luyssen, Videolabs
*
* Authors: Hugo Beauzée-Luyssen<hugo@beauzee.fr>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#pragma once
#include "filesystem/IFile.h"
namespace fs
{
class CommonFile : public IFile
{
public:
CommonFile( const std::string& filePath );
virtual const std::string& name() const override;
virtual const std::string& path() const override;
virtual const std::string& fullPath() const override;
virtual const std::string& extension() const override;
protected:
const std::string m_path;
const std::string m_name;
const std::string m_fullPath;
const std::string m_extension;
};
}
......@@ -21,7 +21,6 @@
*****************************************************************************/
#include "File.h"
#include "Utils.h"
#include <stdexcept>
#include <sys/stat.h>
......@@ -30,10 +29,7 @@ namespace fs
{
File::File( const std::string& filePath )
: m_path( utils::file::directory( filePath ) )
, m_name( utils::file::fileName( filePath ) )
, m_fullPath( filePath )
, m_extension( utils::file::extension( filePath ) )
: CommonFile( filePath )
{
struct stat s;
if ( lstat( m_fullPath.c_str(), &s ) )
......@@ -41,26 +37,6 @@ File::File( const std::string& filePath )
m_lastModificationDate = s.st_mtim.tv_sec;
}
const std::string& File::name() const
{
return m_name;
}
const std::string& File::path() const
{
return m_path;
}
const std::string& File::fullPath() const
{
return m_fullPath;
}
const std::string& File::extension() const
{
return m_extension;
}
unsigned int File::lastModificationDate() const
{
return m_lastModificationDate;
......
......@@ -22,30 +22,19 @@
#pragma once
#include "filesystem/IFile.h"
#include <string>
#include "filesystem/common/CommonFile.h"
namespace fs
{
class File : public IFile
class File : public CommonFile
{
public:
explicit File( const std::string& filePath );
virtual ~File() = default;
virtual const std::string& name() const override;
virtual const std::string& path() const override;
virtual const std::string& fullPath() const override;
virtual const std::string& extension() const override;
virtual unsigned int lastModificationDate() const override;
private:
const std::string m_path;
const std::string m_name;
const std::string m_fullPath;
const std::string m_extension;
unsigned int m_lastModificationDate;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment