-
Notifications
You must be signed in to change notification settings - Fork 35
/
DocumentManager.h
93 lines (68 loc) · 3.31 KB
/
DocumentManager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// MusicXML Class Library
// Copyright (c) by Matthew James Briggs
// Distributed under the MIT License
#pragma once
#include "mx/api/ScoreData.h"
#include <ostream>
#include <memory>
namespace mx
{
namespace core
{
class Document;
using DocumentPtr = std::shared_ptr<Document>;
}
namespace api
{
class DocumentManager
{
public:
DocumentManager( const DocumentManager& other ) = delete;
DocumentManager( DocumentManager&& other ) = delete;
DocumentManager& operator=( const DocumentManager& other ) = delete;
DocumentManager& operator=( DocumentManager&& other ) = delete;
~DocumentManager();
// this class is a singleton, get it like this
// auto& docMngr = DocumentManager::getInstance()
static DocumentManager& getInstance();
// creates a MusicXML document from a file
// and returns the document's ID number, -1 if error
int createFromFile( const std::string& filePath );
// creates a MusicXML document from a character stream
// and returns the document's ID number, -1 if error
int createFromStream( std::istream& stream );
// creates a MusicXML document from a Score structure
// and returns the document's ID number, -1 if error
int createFromScore( const ScoreData& score );
// saves an existing MusicXML document to a
// file, -1 if error
void writeToFile( int documentId, const std::string& filePath ) const;
// saves an existing MusicXML document to a
// character stream, -1 if error
void writeToStream( int documentId, std::ostream& stream ) const;
// retreives the data from an existing document
// and returns it in the Score structure. if id
// does not exist, returns a default Score object
ScoreData getData( int documentId ) const;
// destroys the shared_ptr which is holding the document
// internally and stops tracking ownership of the document
void destroyDocument( int documentId );
// avoid using this function if possible, only use this function
// if your requirements are not met by the Score structure
// note: returns a nullptr if the documentId is bad. if you
// hold a DocumentPtr and call destroyDocument then the
// DocumentManager will no longer know about the object, but the
// object will still exist
mx::core::DocumentPtr getDocument( int documentId ) const;
// returns a unique number and increments the unique number
// generator. this is here as an aid to any client code that
// needs unique numbers since DocumentManager is already a
// thread-locking singleton, it can easily implement this.
int getUniqueId();
private:
DocumentManager();
class Impl;
std::unique_ptr<Impl> myImpl;
};
}
}