Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: shell/src/Main.cpp

Issue 10296001: Implement File API (Closed)
Patch Set: Addressed the new issues Created April 16, 2013, 1:37 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « libadblockplus.gyp ('k') | src/DefaultFileSystem.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include <AdblockPlus.h> 1 #include <AdblockPlus.h>
2 #include <fstream>
3 #include <iostream> 2 #include <iostream>
4 #include <sstream> 3 #include <sstream>
5 4
6 #include "GcCommand.h" 5 #include "GcCommand.h"
7 #include "HelpCommand.h" 6 #include "HelpCommand.h"
8 #include "FiltersCommand.h" 7 #include "FiltersCommand.h"
9 #include "SubscriptionsCommand.h" 8 #include "SubscriptionsCommand.h"
10 #include "MatchesCommand.h" 9 #include "MatchesCommand.h"
11 10
12 namespace 11 namespace
13 { 12 {
14 class LibFileReader : public AdblockPlus::FileReader
15 {
16 public:
17 std::auto_ptr<std::istream> Read(const std::string& path) const
18 {
19 std::ifstream* file = new std::ifstream;
20 file->open(("lib/" + path).c_str());
21 return std::auto_ptr<std::istream>(file);
22 }
23 };
24
25 class CerrErrorCallback : public AdblockPlus::ErrorCallback 13 class CerrErrorCallback : public AdblockPlus::ErrorCallback
26 { 14 {
27 public: 15 public:
28 void operator()(const std::string& message) 16 void operator()(const std::string& message)
29 { 17 {
30 std::cerr << "Error: " << message << std::endl; 18 std::cerr << "Error: " << message << std::endl;
31 } 19 }
32 }; 20 };
33 21
34 void Add(CommandMap& commands, Command* command) 22 void Add(CommandMap& commands, Command* command)
(...skipping 16 matching lines...) Expand all
51 std::istringstream lineStream(commandLine); 39 std::istringstream lineStream(commandLine);
52 lineStream >> name; 40 lineStream >> name;
53 std::getline(lineStream, arguments); 41 std::getline(lineStream, arguments);
54 } 42 }
55 } 43 }
56 44
57 int main() 45 int main()
58 { 46 {
59 try 47 try
60 { 48 {
61 LibFileReader fileReader; 49 AdblockPlus::DefaultFileSystem fileSystem;
62 AdblockPlus::DefaultWebRequest webRequest; 50 AdblockPlus::DefaultWebRequest webRequest;
63 CerrErrorCallback errorCallback; 51 CerrErrorCallback errorCallback;
64 AdblockPlus::JsEngine jsEngine(&fileReader, &webRequest, &errorCallback); 52 AdblockPlus::JsEngine jsEngine(&fileSystem, &webRequest, &errorCallback);
65 AdblockPlus::FilterEngine filterEngine(jsEngine); 53 AdblockPlus::FilterEngine filterEngine(jsEngine);
66 54
67 CommandMap commands; 55 CommandMap commands;
68 Add(commands, new GcCommand(jsEngine)); 56 Add(commands, new GcCommand(jsEngine));
69 Add(commands, new HelpCommand(commands)); 57 Add(commands, new HelpCommand(commands));
70 Add(commands, new FiltersCommand(filterEngine)); 58 Add(commands, new FiltersCommand(filterEngine));
71 Add(commands, new SubscriptionsCommand(filterEngine)); 59 Add(commands, new SubscriptionsCommand(filterEngine));
72 Add(commands, new MatchesCommand(filterEngine)); 60 Add(commands, new MatchesCommand(filterEngine));
73 61
74 std::string commandLine; 62 std::string commandLine;
(...skipping 15 matching lines...) Expand all
90 std::cout << error.what() << std::endl; 78 std::cout << error.what() << std::endl;
91 } 79 }
92 } 80 }
93 } 81 }
94 catch (const std::exception& e) 82 catch (const std::exception& e)
95 { 83 {
96 std::cerr << "Exception: " << e.what() << std::endl; 84 std::cerr << "Exception: " << e.what() << std::endl;
97 } 85 }
98 return 0; 86 return 0;
99 } 87 }
OLDNEW
« no previous file with comments | « libadblockplus.gyp ('k') | src/DefaultFileSystem.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld