Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <vector>
- #include <map>
- #include <algorithm>
- #include <iterator>
- #include <conio.h>
- using namespace std;
- class Music_Player
- {
- private:
- public:
- struct track
- {
- private:
- public:
- int YearConvertFromString(string a)
- {
- int res = 0;
- int crt = 0;
- if (a[0] == '+')
- crt++;
- for (int i = crt; i < a.size(); i++)
- if (isdigit(a[i]))
- res = (res * 10) + (a[i] - '0');
- else
- return -1;
- return res;
- };
- string track_name;
- string performer;
- int year_of_execution;
- track()
- {
- performer = "unknown";
- track_name = "unknown";
- year_of_execution = -1;
- };
- track(string default)
- {
- performer = "unknown";
- track_name = default;
- year_of_execution = -1;
- };
- track(int in_year_of_execution)
- {
- performer = "unknown";
- track_name = "unknown";
- year_of_execution = in_year_of_execution;
- };
- track(string default, int in_year_of_execution)
- {
- performer = "unknown";
- track_name = default;
- year_of_execution = in_year_of_execution;
- }
- track(string in_performer, string in_track_name)
- {
- performer = in_performer;
- track_name = in_track_name;
- year_of_execution = -1;
- };
- track(string in_performer, string in_track_name, int in_year_of_execution)
- {
- performer = in_performer;
- track_name = in_track_name;
- year_of_execution = in_year_of_execution;
- };
- void getTrackFromString(string strInTrackList)
- {
- string prsm;
- int i = 0;
- int end = strInTrackList.length();
- int gapFlag = 1;
- while ((gapFlag == 1) && (i < end))
- {
- performer += strInTrackList[i];
- if ((strInTrackList[i] == ' ') && (strInTrackList[i + 1] == '-'))
- {
- gapFlag = 2;
- i += 3;
- break;
- }
- if ((strInTrackList[i] == ' ') && (strInTrackList[i + 1] == '['))
- {
- gapFlag = 3;;
- i += 3;
- break;
- }
- }
- while ((gapFlag == 2) && (i < end))
- {
- track_name += strInTrackList[i];
- if ((strInTrackList[i] == ' ') && (strInTrackList[i + 1] == '['))
- {
- gapFlag = 3;;
- i += 3;
- break;
- }
- }
- while ((gapFlag == 3) && (i < end))
- {
- prsm += strInTrackList[i];
- if (strInTrackList[i] == ']')
- {
- if (prsm == "")
- year_of_execution = -1;
- else /*newTrack.year_of_execution = atoi(prsm); выдает ошибку,
- пришлось вставлять свой конвертер*/
- year_of_execution = YearConvertFromString(prsm);
- }
- }
- if (i == end)
- if (track_name == "")
- {
- track_name = performer;
- performer = "unknow";
- }
- else
- {
- performer = "error";
- track_name = "error";
- }
- }
- void showTrack()
- {
- cout << performer << " - " << track_name << " [";
- if (year_of_execution != -1)
- cout << year_of_execution << "] ";
- else
- cout << "unknow] ";
- }
- };
- multimap <string, track> track_list;
- //multimap <string, track> track_list;
- void get_track_list_in_multimap()
- {
- string strTrack;
- track test = track();
- ifstream in_track_list("track_list.txt");
- while (in_track_list.peek() != EOF)
- {
- getline(in_track_list, strTrack);
- test.getTrackFromString(strTrack);
- track_list.insert(pair <string, track>(test.performer, test));
- }
- }
- void show_track_list()
- {
- auto iterPair = track_list.equal_range("Edguy");
- if (iterPair.first == iterPair.second)
- cout << "Not found";
- else
- {
- for (auto music_treck = iterPair.first; music_treck != iterPair.second; ++music_treck)
- {
- music_treck->second.showTrack();
- cout << '\n';
- }
- }
- }
- /*
- track getTrack(string strInTrackList, string way)
- {
- ifstream in_track_list(way);
- }
- */
- // о пути к файлу
- /*
- void get_track_list()
- {
- ifstream in_track_list("track_list.txt");
- }*/
- //мультимап
- };
- int main()
- {
- Music_Player myPlayer;
- myPlayer.get_track_list_in_multimap();
- myPlayer.show_track_list();
- //mciSendString("play D:\\Arch Enemy - Nemesis.mp3 wait", NULL, 0, NULL);
- //mciSendString("open \"D:\music2\my music\Arch Enemy - Nemesis.mp3\" type mpegvideo alias mp3", NULL, 0, NULL);
- //_getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement