-
Notifications
You must be signed in to change notification settings - Fork 0
/
mls.cpp
189 lines (157 loc) · 4.91 KB
/
mls.cpp
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#include<iostream>
#include<stdio.h>
#include "LinkedList.h"
void listCommand(LinkedList&);
void setCurrentClip(MusicClipPtr& clip, LinkedList& list, std::string str);
void editPrice(MusicClipPtr& clip, std::string str);
void createClip(MusicClipPtr& clip);
void copyCurrentClip(MusicClipPtr& clip);
void saveCurrentClip(MusicClipPtr& clip);
// void execCommandFile(MusicClipPtr& clip, LinkedList& list);
void commandMessage();
void execCommands();
void execCommands() {
/*Create 10 MusicClipPtr objects*/
MusicClipPtr c0 = MusicClipPtr(0);
MusicClipPtr c1 = MusicClipPtr(1);
MusicClipPtr c2 = MusicClipPtr(2);
MusicClipPtr c3 = MusicClipPtr(3);
MusicClipPtr c4 = MusicClipPtr(4);
MusicClipPtr c5 = MusicClipPtr(5);
MusicClipPtr c6 = MusicClipPtr(6);
MusicClipPtr c7 = MusicClipPtr(7);
MusicClipPtr c8 = MusicClipPtr(8);
MusicClipPtr c9 = MusicClipPtr(9);
/*Create Nodes with MusicClipPtr for LinkedList*/
Node n0 = Node(c0);
Node n1 = Node(c1);
Node n2 = Node(c2);
Node n3 = Node(c3);
Node n4 = Node(c4);
Node n5 = Node(c5);
Node n6 = Node(c6);
Node n7 = Node(c7);
Node n8 = Node(c8);
Node n9 = Node(c9);
/*Initialize Linkedlist and push nodes*/
LinkedList l = LinkedList();
l.push(&n0);
l.push(&n1);
l.push(&n2);
l.push(&n3);
l.push(&n4);
l.push(&n5);
l.push(&n6);
l.push(&n7);
l.push(&n8);
l.push(&n9);
/*Vector of MusicClipPtr& for those that would be loaded in memory*/
// std::vector<MusicClipPtr&> inMemoryClips;
// inMemoryClips.reserve(3);
MusicClipPtr currentClip = l.getHead()->getClip();
int input = 1;
std::string inputstr;
while(input == 1) {
commandMessage();
std::cout << "Enter the command : ";
std::getline(std::cin, inputstr);
switch(inputstr[0]) {
case 'l': listCommand(l);
break;
case 'e': setCurrentClip(currentClip, l, inputstr);
break;
case 'c': createClip(currentClip);
break;
case 'y': copyCurrentClip(currentClip);
break;
case 'i': {
std::ifstream cmdfile("input.inp");
std::string line;
std::vector<std::string> commands;
if(cmdfile.is_open()) {
while(std::getline(cmdfile, line)) {
commands.push_back(line);
line.clear();
}
}
for (int i = 0; i < commands.size(); i++) {
std::string command = commands[i];
std::cout << command << std::endl;
switch(command[0]) {
case 'l': listCommand(l);
break;
case 'e': setCurrentClip(currentClip, l, command);
break;
case 'c': createClip(currentClip);
break;
case 'y': copyCurrentClip(currentClip);
break;
case 'i': break;
case 'p': editPrice(currentClip, command);
break;
case 's': saveCurrentClip(currentClip);
break;
case 'q': input = 0;
break;
default: break;
}
}
}
break;
case 'p': editPrice(currentClip, inputstr);
break;
case 's': saveCurrentClip(currentClip);
break;
case 'q': input = 0;
break;
default: break;
}
}
}
void createClip(MusicClipPtr& clip) {
clip.createClip();
}
void saveCurrentClip(MusicClipPtr& clip) {
clip->displayclip();
clip.saveToFile();
std::cout << "Current Clips saved" << std::endl;
}
void copyCurrentClip(MusicClipPtr& clip) {
clip.dcopy();
std::cout << "Current Clip Copied to File temp.clip" << std::endl;
}
void listCommand(LinkedList& list) {
Node* node = list.getHead();
for(int i = 0; i < 10; i++ ) {
node->getClip()->displayclip();
node = node->getNext();
}
}
void editPrice(MusicClipPtr& clip, std::string str) {
std::string price = str.substr(2);
std::stringstream ss(price);
double d;
ss >> d;
clip->setPrice(d);
std::cout << "Price of current clip changed to " << clip->getPrice() << std::endl;
}
void setCurrentClip(MusicClipPtr& clip, LinkedList& list, std::string str) {
char a = str[2];
int num = a - 48;
Node* node = list.getHead();
for(int i = 0; i < num; i++) {
node = node->getNext();
}
// clip
clip = node->getClip();
std::cout <<"Current clip changed to " << clip->getId() << std::endl;
}
void commandMessage() {
std::cout << "Enter the commands in following formats " << std::endl;
std::cout << "l to list all music clips" <<std::endl << "e <index> to edit the clip of index" << std::endl << "c to create a clip" << std::endl << "y to copy current clip to temp" << std::endl << "i to read commands from input file" << std::endl << "p to change price of the current clip" << std::endl << "s to save all clips" << std::endl << "q to quit MLS" << std::endl;
}
int main() {
std::cout << "::: Welcome to Music Library System :::" << std::endl;
execCommands();
return 0;
}