grive2/libgrive/src/drive/Resource.hh

80 lines
1.9 KiB
C++
Raw Normal View History

/*
grive: an GPL program to sync a local directory with Google Drive
Copyright (C) 2012 Wan Wai Ho
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation version 2
of the License.
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 General Public License for more details.
You should have received a copy of the GNU 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
2012-05-09 19:52:06 +04:00
#include "Entry.hh"
2012-05-13 11:27:58 +04:00
#include "util/Exception.hh"
2012-05-16 21:20:02 +04:00
#include "util/FileSystem.hh"
#include <string>
#include <vector>
namespace gr {
2012-05-13 21:07:23 +04:00
class File ;
2012-05-19 11:41:21 +04:00
class Resource
{
public :
2012-05-19 11:41:21 +04:00
explicit Resource( const xml::Node& entry ) ;
explicit Resource( const Entry& entry ) ;
Resource( const std::string& title, const std::string& href ) ;
Resource( const std::string& title, Resource *parent ) ;
// default copy ctor & op= are fine
2012-05-09 19:52:06 +04:00
std::string Title() const ;
std::string SelfHref() const ;
2012-05-19 11:41:21 +04:00
const Resource* Parent() const ;
Resource* Parent() ;
2012-05-09 19:52:06 +04:00
std::string ParentHref() const ;
2012-05-16 21:20:02 +04:00
fs::path Dir() const ;
bool IsInRootTree() const ;
2012-05-17 20:37:11 +04:00
std::string ResourceID() const ;
2012-05-19 11:41:21 +04:00
void AddChild( Resource *child ) ;
2012-05-13 21:07:23 +04:00
void AddLeaf( File *file ) ;
2012-05-19 11:41:21 +04:00
void Swap( Resource& coll ) ;
// traversing the tree
2012-05-16 21:20:02 +04:00
void CreateSubDir( const fs::path& prefix ) ;
2012-05-13 11:27:58 +04:00
struct Error : virtual Exception {} ;
2012-05-19 11:41:21 +04:00
Resource* FindChild( const std::string& title ) ;
2012-05-17 20:37:11 +04:00
void Update( const Entry& e ) ;
private :
2012-05-09 19:52:06 +04:00
Entry m_entry ;
// not owned
2012-05-19 11:41:21 +04:00
Resource *m_parent ;
std::vector<Resource*> m_child ;
std::vector<File*> m_leaf ;
} ;
} // end of namespace
namespace std
{
2012-05-19 11:41:21 +04:00
void swap( gr::Resource& c1, gr::Resource& c2 ) ;
}