Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Created by Nguyen Duc Dung on 2019-09-03.
- * =========================================================================================
- * Name : processData.cpp
- * Author : Duc Dung Nguyen
- * Email : [email protected]
- * Copyright : Faculty of Computer Science and Engineering - HCMUT
- * Description : Implementation of main features in the assignment
- * Course : Data Structure and Algorithms - Fall 2019
- * =========================================================================================
- */
- #include "processData.h"
- #include "dbLib.h"
- /* TODO: You can implement methods, functions that support your data structures here.
- * */
- int* temp;
- using namespace std;
- template <typename T>
- void PrintReqOutput(const char* pRequest, T* pOutput, int N) {
- cout << pRequest << ":";
- if (pOutput == nullptr) {
- cout << " error\n";
- return;
- }
- for (int i = 0; i < N; ++i) {
- cout << ' ' << *pOutput++;
- }
- cout << '\n';
- }
- void Initialization() {
- // If you use global variables, please initialize them explicitly in this function.
- }
- void Finalization() {
- // Release your data before exiting
- }
- void ProcessRequest(const char* pRequest, void* pData, void*& pOutput, int& N) {
- // TODO: Implement this function for processing a request
- // NOTE: You can add other functions to support this main process.
- // pData is a pointer to a data structure that manages the dataset
- // pOutput is a pointer reference. It is set to nullptr and student must allocate data for it in order to save the required output
- // N is the size of output, must be a non-negative number
- int* temp = new int(0);
- TDataset* ptr = static_cast<TDataset*>(pData);
- N = 1;
- string req = pRequest;
- if (req == "CL")
- *temp = GetNumOfLine(ptr->LLine);
- else if (req[0] == 'C' && req[1] == 'L')
- {
- string str_temp = req.substr(3);
- *temp = countLinesInCity(ptr, str_temp);
- }
- else if (req[0] == 'L' && req[1] == 'S' && req[2] == 'C')
- {
- string str_temp = req.substr(4);
- temp = listStationInCity(ptr, str_temp);
- }
- else if (req[0] == 'L' && req[1] == 'L' && req[2] == 'C')
- {
- string str_temp = req.substr(4);
- temp = listLinesInCity(ptr, str_temp);
- }
- else if (req[0] == 'L' && req[1] == 'S' && req[2] == 'L')
- {
- string str_temp = req.substr(4);
- temp = listStaionLines(ptr, str_temp);
- }
- else if (req[0] == 'F' && req[1] == 'C')
- {
- string str_temp = req.substr(3);
- *temp = findIDCity(ptr, str_temp);
- }
- else if (req[0] == 'F' && req[1] == 'S')
- {
- string str_temp = req.substr(3);
- *temp = findStationID(ptr, str_temp);
- }
- else if (req[0] == 'S' && req[0] == 'L' && req[0] == 'P')
- {
- int i = 0, t = 0;
- int arr[2];
- string str_temp;
- while (i < req.length())
- {
- if (req[i] == ' ')
- {
- i++;
- while (req[i] != ' ')
- {
- str_temp += req[i];
- i++;
- }
- arr[t++] = stoi(str_temp);
- str_temp = "";
- }
- i++;
- }
- *temp = findStationFromTrack(ptr, arr[0], arr[1]);
- }
- else if (req[0] == 'I' && req[1] == 'S' && req[2] != 'L')
- {
- string str_temp = req.substr(3);
- *temp = insertNewStation(str_temp, ptr);
- }
- else if (req[0] == 'R' && req[1] == 'S' && req[2] != 'L')
- {
- string str_temp = req.substr(3);
- int input = stoi(str_temp);
- *temp = removeStation(ptr, input);
- }
- else if (req[0] == 'U' && req[0] == 'S')
- {
- int a;
- string str_temp;
- int i = 0;
- while (req[i] != ' ')
- {
- i++;
- }
- i++;
- while (req[i] != ' ')
- {
- str_temp = str_temp + req[i];
- i++;
- }
- a = stoi(str_temp);
- i++;
- str_temp = "";
- while (i < req.length())
- {
- str_temp = str_temp + req[i];
- i++;
- }
- *temp = updateStation(a, str_temp, ptr);
- }
- else if (req[0] == 'I' && req[1] == 'S' && req[2] == 'L')
- {
- int a, b, c;
- string str_temp;
- int i = 0;
- while (req[i] != ' ')
- i++;
- i++;
- while (req[i] != ' ')
- {
- str_temp += req[i];
- i++;
- }
- a = stoi(str_temp);
- i++;
- str_temp = "";
- while (req[i] != ' ')
- {
- str_temp += req[i];
- i++;
- }
- b = stoi(str_temp);
- i++;
- str_temp = "";
- while (req[i] != ' ')
- {
- str_temp += req[i];
- i++;
- }
- c = stoi(str_temp);
- *temp = insertStationLines(ptr, a, b, c);
- }
- else if (req[0] == 'R' && req[1] == 'S' && req[2] == 'L')
- {
- int a, b;
- string str_temp;
- int i = 0;
- while (req[i] != ' ')
- i++;
- i++;
- while (req[i] != ' ')
- {
- str_temp = str_temp + req[i];
- i++;
- }
- a = stoi(str_temp);
- i++;
- str_temp = req.substr(i);
- b = stoi(str_temp);
- *temp = removeStationLines(ptr, a, b);
- }
- pOutput = temp;
- }
Advertisement
Add Comment
Please, Sign In to add comment