{"action":"created","comment":{"url":"https://api.github.com/repos/abdelm/uts/pulls/comments/65000060","id":65000060,"diff_hunk":"@@ -0,0 +1,273 @@\n+//\n+//  MorseCode.h\n+//  dsa_assign2\n+//\n+//  Created by Abdelrahman Ahmed on 21/05/2016.\n+//  Copyright © 2016 Abdelrahman Ahmed. All rights reserved.\n+//\n+\n+#ifndef MorseCode_h\n+#define MorseCode_h\n+#define morseCodeSource \"/Users/Abdel/Projects/uts/dsa/assignments/dsa_assign2/dsa_assign2/morsecodes.txt\"\n+\n+#include <list>\n+#include <string>\n+#include <cctype>\n+#include <vector>\n+#include <sstream>\n+#include <fstream>\n+#include <iostream>\n+#include <stdexcept>\n+#include <algorithm>\n+#include \"bintree.h\"\n+\n+using namespace std;\n+\n+class MorseCode\n+{\n+   private:\n+      struct englishToMorse\n+      {\n+         char letter;\n+         string morse;\n+         \n+         bool operator ==(char l) const\n+         {\n+            return letter == l;\n+         }\n+      };\n+   \n+      struct morseToEnglish\n+      {\n+         string morse;\n+         char letter;\n+         \n+         bool operator ==(const morseToEnglish& l) const\n+         {\n+            return morse == l.morse;\n+         }\n+         \n+         bool operator <(const morseToEnglish& l) const\n+         {\n+            return morse < l.morse;\n+         }\n+      };\n+\n+      // Vector for morse codes\n+      vector<englishToMorse> vectorMorse;\n+\n+      // Binary tree for morse codes\n+      treespc::bintree<morseToEnglish> bintreeMorse;\n+   \n+      // Code (either e or d)\n+      char code;\n+\n+      // Input file\n+      const char * filein;\n+   \n+      // Output file\n+      const char * fileout;\n+   \n+      void loadSource()\n+      {\n+         string line;\n+         ifstream source;\n+         \n+         // Open stream to file\n+         source.open(morseCodeSource);\n+         \n+         // Check if file can be read\n+         if (!source.is_open())\n+         {\n+            throw runtime_error(\"ERROR unable to read file\");\n+         }\n+         \n+         // Read line by line\n+         while (getline(source, line))\n+         {\n+            char letter;\n+            string morse;\n+            stringstream linestream(line);\n+            \n+            // Split line into letter and associated morse code\n+            linestream >> letter >> morse;\n+            \n+            // Encoding\n+            if (code == 'e')\n+            {\n+               // Init struct values\n+               englishToMorse data;\n+               data.letter = letter;\n+               data.morse = morse;\n+               \n+               // Add to vector\n+               vectorMorse.push_back(data);\n+            }\n+            \n+            // Decoding\n+            else if (code == 'd')\n+            {\n+               // Init struct values\n+               morseToEnglish data;\n+               data.morse = morse;\n+               data.letter = letter;\n+               \n+               // Add to binary tree\n+               bintreeMorse.insert(data);\n+            }\n+         }\n+         \n+         // Close file\n+         source.close();\n+      }\n+   \n+      void encode()\n+      {\n+         char c;\n+         ifstream in;\n+         ofstream out;\n+         \n+         // Open stream to file\n+         in.open(filein);\n+         out.open(fileout);\n+         \n+         // Check if file can be read\n+         if (!in.is_open())\n+         {\n+            throw runtime_error(\"ERROR unable to read file\");\n+         }\n+         \n+         // Check if we're on a new line\n+         bool newLine = true;\n+         \n+         // Read character by character\n+         while (in.get(c))\n+         {\n+            // Ignore Windows linebreaks\n+            if (in.good() && c != '\\r')\n+            {\n+               vector<englishToMorse>::iterator iter;\n+               iter = find(vectorMorse.begin(), vectorMorse.end(), c);\n+               \n+               // Print newline character\n+               if (c == '\\n')\n+               {\n+                  out << endl;\n+                  newLine = true;\n+               }\n+               \n+               // Or, print a space\n+               else if (c == ' ')\n+               {\n+                  out << \" \";\n+               }\n+               \n+               // Or, print the morse code\n+               else if (iter != vectorMorse.end())\n+               {\n+                  // To avoid trailing space, print morse with preceding space\n+                  if (newLine == false) out << \" \" << iter->morse;\n+                  \n+                  // If beginning new line, print without a space\n+                  else\n+                  {\n+                     out << iter->morse;\n+                     newLine = false;\n+                  }\n+               }\n+            }\n+         }\n+         \n+         // Close all connections\n+         in.close();\n+         out.close();\n+      }\n+      \n+      void decode()\n+      {\n+         ifstream in;\n+         ofstream out;\n+         \n+         // Open stream to file\n+         in.open(filein);","path":"dsa/assignments/dsa_assign2_review/dsa_assign2/MorseCode.h","position":131,"original_position":192,"commit_id":"6e11198af7f75369625e2097d9ac847f5e0cc4c5","original_commit_id":"6e11198af7f75369625e2097d9ac847f5e0cc4c5","user":{"login":"connordavison","id":6268351,"avatar_url":"https://avatars.githubusercontent.com/u/6268351?v=3","gravatar_id":"","url":"https://api.github.com/users/connordavison","html_url":"https://github.com/connordavison","followers_url":"https://api.github.com/users/connordavison/followers","following_url":"https://api.github.com/users/connordavison/following{/other_user}","gists_url":"https://api.github.com/users/connordavison/gists{/gist_id}","starred_url":"https://api.github.com/users/connordavison/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/connordavison/subscriptions","organizations_url":"https://api.github.com/users/connordavison/orgs","repos_url":"https://api.github.com/users/connordavison/repos","events_url":"https://api.github.com/users/connordavison/events{/privacy}","received_events_url":"https://api.github.com/users/connordavison/received_events","type":"User","site_admin":false},"body":"Again, inject these as parameters and just confirm `is_open()` before processing.","created_at":"2016-05-29T09:17:47Z","updated_at":"2016-05-29T09:17:47Z","html_url":"https://github.com/abdelm/uts/pull/1#discussion_r65000060","pull_request_url":"https://api.github.com/repos/abdelm/uts/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/abdelm/uts/pulls/comments/65000060"},"html":{"href":"https://github.com/abdelm/uts/pull/1#discussion_r65000060"},"pull_request":{"href":"https://api.github.com/repos/abdelm/uts/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/abdelm/uts/pulls/1","id":71821408,"html_url":"https://github.com/abdelm/uts/pull/1","diff_url":"https://github.com/abdelm/uts/pull/1.diff","patch_url":"https://github.com/abdelm/uts/pull/1.patch","issue_url":"https://api.github.com/repos/abdelm/uts/issues/1","number":1,"state":"open","locked":false,"title":"Review","user":{"login":"connordavison","id":6268351,"avatar_url":"https://avatars.githubusercontent.com/u/6268351?v=3","gravatar_id":"","url":"https://api.github.com/users/connordavison","html_url":"https://github.com/connordavison","followers_url":"https://api.github.com/users/connordavison/followers","following_url":"https://api.github.com/users/connordavison/following{/other_user}","gists_url":"https://api.github.com/users/connordavison/gists{/gist_id}","starred_url":"https://api.github.com/users/connordavison/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/connordavison/subscriptions","organizations_url":"https://api.github.com/users/connordavison/orgs","repos_url":"https://api.github.com/users/connordavison/repos","events_url":"https://api.github.com/users/connordavison/events{/privacy}","received_events_url":"https://api.github.com/users/connordavison/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-05-29T08:24:03Z","updated_at":"2016-05-29T09:17:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0b6237efed88cea258637f7186c56ced0bd8a7e0","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/abdelm/uts/pulls/1/commits","review_comments_url":"https://api.github.com/repos/abdelm/uts/pulls/1/comments","review_comment_url":"https://api.github.com/repos/abdelm/uts/pulls/comments{/number}","comments_url":"https://api.github.com/repos/abdelm/uts/issues/1/comments","statuses_url":"https://api.github.com/repos/abdelm/uts/statuses/6e11198af7f75369625e2097d9ac847f5e0cc4c5","head":{"label":"connordavison:master","ref":"master","sha":"6e11198af7f75369625e2097d9ac847f5e0cc4c5","user":{"login":"connordavison","id":6268351,"avatar_url":"https://avatars.githubusercontent.com/u/6268351?v=3","gravatar_id":"","url":"https://api.github.com/users/connordavison","html_url":"https://github.com/connordavison","followers_url":"https://api.github.com/users/connordavison/followers","following_url":"https://api.github.com/users/connordavison/following{/other_user}","gists_url":"https://api.github.com/users/connordavison/gists{/gist_id}","starred_url":"https://api.github.com/users/connordavison/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/connordavison/subscriptions","organizations_url":"https://api.github.com/users/connordavison/orgs","repos_url":"https://api.github.com/users/connordavison/repos","events_url":"https://api.github.com/users/connordavison/events{/privacy}","received_events_url":"https://api.github.com/users/connordavison/received_events","type":"User","site_admin":false},"repo":{"id":59933430,"name":"uts","full_name":"connordavison/uts","owner":{"login":"connordavison","id":6268351,"avatar_url":"https://avatars.githubusercontent.com/u/6268351?v=3","gravatar_id":"","url":"https://api.github.com/users/connordavison","html_url":"https://github.com/connordavison","followers_url":"https://api.github.com/users/connordavison/followers","following_url":"https://api.github.com/users/connordavison/following{/other_user}","gists_url":"https://api.github.com/users/connordavison/gists{/gist_id}","starred_url":"https://api.github.com/users/connordavison/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/connordavison/subscriptions","organizations_url":"https://api.github.com/users/connordavison/orgs","repos_url":"https://api.github.com/users/connordavison/repos","events_url":"https://api.github.com/users/connordavison/events{/privacy}","received_events_url":"https://api.github.com/users/connordavison/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/connordavison/uts","description":"Assignments or random code during my time at UTS.","fork":true,"url":"https://api.github.com/repos/connordavison/uts","forks_url":"https://api.github.com/repos/connordavison/uts/forks","keys_url":"https://api.github.com/repos/connordavison/uts/keys{/key_id}","collaborators_url":"https://api.github.com/repos/connordavison/uts/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/connordavison/uts/teams","hooks_url":"https://api.github.com/repos/connordavison/uts/hooks","issue_events_url":"https://api.github.com/repos/connordavison/uts/issues/events{/number}","events_url":"https://api.github.com/repos/connordavison/uts/events","assignees_url":"https://api.github.com/repos/connordavison/uts/assignees{/user}","branches_url":"https://api.github.com/repos/connordavison/uts/branches{/branch}","tags_url":"https://api.github.com/repos/connordavison/uts/tags","blobs_url":"https://api.github.com/repos/connordavison/uts/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/connordavison/uts/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/connordavison/uts/git/refs{/sha}","trees_url":"https://api.github.com/repos/connordavison/uts/git/trees{/sha}","statuses_url":"https://api.github.com/repos/connordavison/uts/statuses/{sha}","languages_url":"https://api.github.com/repos/connordavison/uts/languages","stargazers_url":"https://api.github.com/repos/connordavison/uts/stargazers","contributors_url":"https://api.github.com/repos/connordavison/uts/contributors","subscribers_url":"https://api.github.com/repos/connordavison/uts/subscribers","subscription_url":"https://api.github.com/repos/connordavison/uts/subscription","commits_url":"https://api.github.com/repos/connordavison/uts/commits{/sha}","git_commits_url":"https://api.github.com/repos/connordavison/uts/git/commits{/sha}","comments_url":"https://api.github.com/repos/connordavison/uts/comments{/number}","issue_comment_url":"https://api.github.com/repos/connordavison/uts/issues/comments{/number}","contents_url":"https://api.github.com/repos/connordavison/uts/contents/{+path}","compare_url":"https://api.github.com/repos/connordavison/uts/compare/{base}...{head}","merges_url":"https://api.github.com/repos/connordavison/uts/merges","archive_url":"https://api.github.com/repos/connordavison/uts/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/connordavison/uts/downloads","issues_url":"https://api.github.com/repos/connordavison/uts/issues{/number}","pulls_url":"https://api.github.com/repos/connordavison/uts/pulls{/number}","milestones_url":"https://api.github.com/repos/connordavison/uts/milestones{/number}","notifications_url":"https://api.github.com/repos/connordavison/uts/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/connordavison/uts/labels{/name}","releases_url":"https://api.github.com/repos/connordavison/uts/releases{/id}","deployments_url":"https://api.github.com/repos/connordavison/uts/deployments","created_at":"2016-05-29T08:22:29Z","updated_at":"2016-05-29T08:22:30Z","pushed_at":"2016-05-29T08:23:28Z","git_url":"git://github.com/connordavison/uts.git","ssh_url":"git@github.com:connordavison/uts.git","clone_url":"https://github.com/connordavison/uts.git","svn_url":"https://github.com/connordavison/uts","homepage":"","size":56,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"abdelm:master","ref":"master","sha":"25a13bebe2a51dd471041007aef1a28771c856f1","user":{"login":"abdelm","id":181392,"avatar_url":"https://avatars.githubusercontent.com/u/181392?v=3","gravatar_id":"","url":"https://api.github.com/users/abdelm","html_url":"https://github.com/abdelm","followers_url":"https://api.github.com/users/abdelm/followers","following_url":"https://api.github.com/users/abdelm/following{/other_user}","gists_url":"https://api.github.com/users/abdelm/gists{/gist_id}","starred_url":"https://api.github.com/users/abdelm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abdelm/subscriptions","organizations_url":"https://api.github.com/users/abdelm/orgs","repos_url":"https://api.github.com/users/abdelm/repos","events_url":"https://api.github.com/users/abdelm/events{/privacy}","received_events_url":"https://api.github.com/users/abdelm/received_events","type":"User","site_admin":false},"repo":{"id":54343582,"name":"uts","full_name":"abdelm/uts","owner":{"login":"abdelm","id":181392,"avatar_url":"https://avatars.githubusercontent.com/u/181392?v=3","gravatar_id":"","url":"https://api.github.com/users/abdelm","html_url":"https://github.com/abdelm","followers_url":"https://api.github.com/users/abdelm/followers","following_url":"https://api.github.com/users/abdelm/following{/other_user}","gists_url":"https://api.github.com/users/abdelm/gists{/gist_id}","starred_url":"https://api.github.com/users/abdelm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abdelm/subscriptions","organizations_url":"https://api.github.com/users/abdelm/orgs","repos_url":"https://api.github.com/users/abdelm/repos","events_url":"https://api.github.com/users/abdelm/events{/privacy}","received_events_url":"https://api.github.com/users/abdelm/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/abdelm/uts","description":"Assignments or random code during my time at UTS.","fork":false,"url":"https://api.github.com/repos/abdelm/uts","forks_url":"https://api.github.com/repos/abdelm/uts/forks","keys_url":"https://api.github.com/repos/abdelm/uts/keys{/key_id}","collaborators_url":"https://api.github.com/repos/abdelm/uts/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/abdelm/uts/teams","hooks_url":"https://api.github.com/repos/abdelm/uts/hooks","issue_events_url":"https://api.github.com/repos/abdelm/uts/issues/events{/number}","events_url":"https://api.github.com/repos/abdelm/uts/events","assignees_url":"https://api.github.com/repos/abdelm/uts/assignees{/user}","branches_url":"https://api.github.com/repos/abdelm/uts/branches{/branch}","tags_url":"https://api.github.com/repos/abdelm/uts/tags","blobs_url":"https://api.github.com/repos/abdelm/uts/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/abdelm/uts/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/abdelm/uts/git/refs{/sha}","trees_url":"https://api.github.com/repos/abdelm/uts/git/trees{/sha}","statuses_url":"https://api.github.com/repos/abdelm/uts/statuses/{sha}","languages_url":"https://api.github.com/repos/abdelm/uts/languages","stargazers_url":"https://api.github.com/repos/abdelm/uts/stargazers","contributors_url":"https://api.github.com/repos/abdelm/uts/contributors","subscribers_url":"https://api.github.com/repos/abdelm/uts/subscribers","subscription_url":"https://api.github.com/repos/abdelm/uts/subscription","commits_url":"https://api.github.com/repos/abdelm/uts/commits{/sha}","git_commits_url":"https://api.github.com/repos/abdelm/uts/git/commits{/sha}","comments_url":"https://api.github.com/repos/abdelm/uts/comments{/number}","issue_comment_url":"https://api.github.com/repos/abdelm/uts/issues/comments{/number}","contents_url":"https://api.github.com/repos/abdelm/uts/contents/{+path}","compare_url":"https://api.github.com/repos/abdelm/uts/compare/{base}...{head}","merges_url":"https://api.github.com/repos/abdelm/uts/merges","archive_url":"https://api.github.com/repos/abdelm/uts/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/abdelm/uts/downloads","issues_url":"https://api.github.com/repos/abdelm/uts/issues{/number}","pulls_url":"https://api.github.com/repos/abdelm/uts/pulls{/number}","milestones_url":"https://api.github.com/repos/abdelm/uts/milestones{/number}","notifications_url":"https://api.github.com/repos/abdelm/uts/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/abdelm/uts/labels{/name}","releases_url":"https://api.github.com/repos/abdelm/uts/releases{/id}","deployments_url":"https://api.github.com/repos/abdelm/uts/deployments","created_at":"2016-03-20T22:20:50Z","updated_at":"2016-04-14T07:05:46Z","pushed_at":"2016-05-29T08:24:04Z","git_url":"git://github.com/abdelm/uts.git","ssh_url":"git@github.com:abdelm/uts.git","clone_url":"https://github.com/abdelm/uts.git","svn_url":"https://github.com/abdelm/uts","homepage":"","size":54,"stargazers_count":1,"watchers_count":1,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/abdelm/uts/pulls/1"},"html":{"href":"https://github.com/abdelm/uts/pull/1"},"issue":{"href":"https://api.github.com/repos/abdelm/uts/issues/1"},"comments":{"href":"https://api.github.com/repos/abdelm/uts/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/abdelm/uts/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/abdelm/uts/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/abdelm/uts/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/abdelm/uts/statuses/6e11198af7f75369625e2097d9ac847f5e0cc4c5"}}}}
{"actor":{"display_login":"connordavison"}}