#include <Node.h>

Inheritance diagram for giga::core::Node:
giga::core::FileNode giga::core::FolderNode

Public Types

enum  Type { root = 0, folder, file }
 
enum  MediaType {
  audio = 0, document, video, image,
  unknown, folder
}
 
enum  MergePolicy { override = 0, ignore, renameSource, renameDest }
 
typedef std::unique_ptr
< std::pair< std::unique_ptr
< Sha1Calculator >, pplx::task
< std::shared_ptr
< FileUploader > > > > 
UploadingFile
 

Public Member Functions

 Node (Node &&)=default
 
Nodeoperator= (Node &&)=default
 
 Node (const Node &rhs)
 
Nodeoperator= (const Node &rhs)
 
const std::string & id () const
 
Type type () const
 
const utility::string_t & name () const
 
const std::string & parentId () const
 
const std::vector< std::string > & ancestors () const
 
uint64_t ownerId () const
 
std::chrono::system_clock::time_point creationDate () const
 
std::chrono::system_clock::time_point lastUpdateDate () const
 
uint64_t nbChildren () const
 
uint64_t nbFiles () const
 
uint64_t size () const
 
virtual const std::vector
< std::unique_ptr< Node > > & 
getChildren () const =0
 Load the children node if needed then return them. The children nodes are stored in a local cache variable. More...
 
virtual FolderNodeaddChildFolder (const utility::string_t &name)=0
 Create a new FolderNode and add it to the children list. More...
 
virtual FolderNode createChildFolder (const utility::string_t &name) const =0
 Create a new FolderNode (Do not add it to the local children list) More...
 
virtual UploadingFile uploadFile (const boost::filesystem::path &filepath, pplx::cancellation_token_source cts=pplx::cancellation_token_source{})=0
 Upload a file into this FolderNode. More...
 
virtual FileDownloader download (const utility::string_t &destinationPath, FileDownloader::Policy policy=FileDownloader::Policy::ignore)=0
 Download a FileNode. More...
 
virtual const FileNodeDatafileData () const =0
 Get the data associated with a FileNode. More...
 
void remove ()
 Remove this node. Set its id to "" More...
 
const utility::string_t & rename (const utility::string_t &name)
 Rename this node. More...
 
std::unique_ptr< core::NodecopyTo (const FolderNode &node, MergePolicy policy=MergePolicy::renameSource) const
 Shortcut for copyOrMoveTo(const FolderNode&, false, MergePolicy)
 
std::unique_ptr< core::NodemoveTo (const FolderNode &node, MergePolicy policy=MergePolicy::renameSource) const
 Shortcut for copyOrMoveTo(const FolderNode&, bool, MergePolicy)
 
std::unique_ptr< core::NodecopyOrMoveTo (const FolderNode &node, bool isMove, MergePolicy policy=MergePolicy::renameSource) const
 Copy or move a node. More...
 
const std::shared_ptr< data::Nodehandle () const
 

Static Public Member Functions

static std::unique_ptr< Nodecreate (std::shared_ptr< data::Node > n, const Application &app)
 
static std::unique_ptr< Nodecreate (const Node &node)
 

Static Public Attributes

static const
utils::EnumConvertor
< core::Node::Type, 3 > 
typeCvrt
 
static const
utils::EnumConvertor
< MediaType, 6 > 
mediaTypeCvrt
 
static const
utils::EnumConvertor
< MergePolicy, 4 > 
mergePolicyCvrt
 

Protected Member Functions

 Node (std::shared_ptr< data::Node > n, const Application &app)
 

Protected Attributes

std::shared_ptr< data::Node_data
 
const Application_app
 

Detailed Description

The class Node represents a file or a folder. It is the base class of a composite pattern, with the FileNode and FolderNode classes.

Member Enumeration Documentation

The MergePolicy is used when inserting / uploading / copying / moving files and folders. It dictate what to do when there is a name conflict between 2 files / folders.

The possible values are :

  • override : Override the destination file with the file being copied/moved/...
  • ignore : Ignore the copy/move/... and keep the destination file
  • renameSource : Rename the file being copied/moved/... before inserting it.
  • renameDest : Rename the conflicting file in the destination folder before inserting the new file.

The way the mergePolicy is applied is different whether it's applied on files or folders:

Destination: File Destination: Folder
Source: File Use policy (Ignore on same files)₁ Use policy (renameSource on override)₂
Source: Folder Use policy (renameSource on override)₂Always merge the 2 folders.₃
  • 1) If the 2 files are the same, the specified policy is ignored, and ignore policy is used instead. If the 2 files are different, the policy is used as specified.
  • 2) When there is a folder/file or file/folder conflict, even if the override policy is specified, no file/folder gets overridden. In this case, the renameSource policy is used instead of the override policy
  • 3) When there is a folder/folder conflict, the policy is ignored, and the 2 folder are merged together.

Member Function Documentation

virtual FolderNode& giga::core::Node::addChildFolder ( const utility::string_t &  name)
pure virtual

Create a new FolderNode and add it to the children list.

Returns
The new FolderNode
Exceptions
HttpError

Implemented in giga::core::FileNode, and giga::core::FolderNode.

std::unique_ptr< core::Node > giga::core::Node::copyOrMoveTo ( const FolderNode node,
bool  isMove,
MergePolicy  policy = MergePolicy::renameSource 
) const

Copy or move a node.

  • If this is a file and node contains a file with the same name, the policy is used
  • If this is a folder and node contains a folder with the same name, the two folders will be merged..
  • For more information on merge policy see giga::core::Node::MergePolicy

The copy/move operation is a long lasting operation (more than 1s). The operation will timeout after 465 seconds

Parameters
nodeis the destination folder. You may want to reload node (uses Application::getNodeById())
isMovetrue for a move, false for a copy
policythe merge policy is used when there are name conflicts.
Returns
the copied or move node (this node should not be used after being moved)
virtual FolderNode giga::core::Node::createChildFolder ( const utility::string_t &  name) const
pure virtual

Create a new FolderNode (Do not add it to the local children list)

Returns
The new FolderNode
Exceptions
HttpError

Implemented in giga::core::FileNode, and giga::core::FolderNode.

virtual FileDownloader giga::core::Node::download ( const utility::string_t &  destinationPath,
FileDownloader::Policy  policy = FileDownloader::Policy::ignore 
)
pure virtual

Download a FileNode.

Parameters
destinationPatha path to a folder where the FileNode will be downloaded
policywhat to do if the file already exists at destinationPath
Returns
A FileDownloader to control the download.
Exceptions
ErrorExceptionif this node is a FolderNode
See Also
Downloader to download folders.

Implemented in giga::core::FileNode, and giga::core::FolderNode.

virtual const FileNodeData& giga::core::Node::fileData ( ) const
pure virtual

Get the data associated with a FileNode.

Exceptions
ErrorExceptionif this node is a FolderNode

Implemented in giga::core::FileNode, and giga::core::FolderNode.

virtual const std::vector<std::unique_ptr<Node> >& giga::core::Node::getChildren ( ) const
pure virtual

Load the children node if needed then return them. The children nodes are stored in a local cache variable.

Returns
The list of children nodes
Exceptions
HttpError

Implemented in giga::core::FileNode, and giga::core::FolderNode.

void giga::core::Node::remove ( )

Remove this node. Set its id to ""

Exceptions
HttpError
const utility::string_t & giga::core::Node::rename ( const utility::string_t &  name)

Rename this node.

The new name may be different from the name parameter (some characters may be changed to have a valid filename).

Parameters
namemust not exceed 255 chars
Returns
The new name.
Exceptions
HttpError
ErrorExceptionif the name is not valid.
virtual UploadingFile giga::core::Node::uploadFile ( const boost::filesystem::path &  filepath,
pplx::cancellation_token_source  cts = pplx::cancellation_token_source{} 
)
pure virtual

Upload a file into this FolderNode.

Parameters
filepaththe path to the file to upload
Returns
A FileUploader object to control the upload.
Exceptions
ErrorExceptionif this node is a FileNode.
See Also
Uploader to upload folders.

Implemented in giga::core::FileNode, and giga::core::FolderNode.

Member Data Documentation

const utils::EnumConvertor< core::Node::MediaType, 6 > giga::core::Node::mediaTypeCvrt
static
Initial value:
=
{U("audio"), U("document"), U("video"), U("image"), U("unknown"), U("folder")}
const utils::EnumConvertor< core::Node::MergePolicy, 4 > giga::core::Node::mergePolicyCvrt
static
Initial value:
=
{U("override"), U("ignore"), U("renameSource"), U("renameDest")}
const utils::EnumConvertor< core::Node::Type, 3 > giga::core::Node::typeCvrt
static
Initial value:
=
{U("root"), U("folder"), U("file")}

The documentation for this class was generated from the following files:
  • /home/thomas/code/GiGaSdk/src/giga/core/Node.h
  • /home/thomas/code/GiGaSdk/src/giga/core/Node.cpp