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

Delta Between Two Patch Sets: shell/src/Main.cpp

Issue 10296001: Implement File API (Closed)
Left Patch Set: Don't pass a blog to _fileSystem.write Created April 12, 2013, 12:10 p.m.
Right 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « libadblockplus.gyp ('k') | src/DefaultFileSystem.cpp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 LibFileSystem : public AdblockPlus::FileSystem
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());
Wladimir Palant 2013/04/12 16:10:35 I don't think this dummy implementation is useful.
Felix Dahlke 2013/04/15 03:43:34 Fair enough, will do that.
21 return std::auto_ptr<std::istream>(file);
22 }
23
24 void Write(const std::string& path, const std::string& content)
25 {
26 throw std::runtime_error("Write is not implemented");
27 }
28
29 void Move(const std::string& fromPath, const std::string& toPath)
30 {
31 throw std::runtime_error("Move is not implemented");
32 }
33
34 void Remove(const std::string& path)
35 {
36 throw std::runtime_error("Remove is not implemented");
37 }
38
39 StatResult Stat(const std::string& path) const
40 {
41 throw std::runtime_error("Stat is not implemented");
42 }
43 };
44
45 class CerrErrorCallback : public AdblockPlus::ErrorCallback 13 class CerrErrorCallback : public AdblockPlus::ErrorCallback
46 { 14 {
47 public: 15 public:
48 void operator()(const std::string& message) 16 void operator()(const std::string& message)
49 { 17 {
50 std::cerr << "Error: " << message << std::endl; 18 std::cerr << "Error: " << message << std::endl;
51 } 19 }
52 }; 20 };
53 21
54 void Add(CommandMap& commands, Command* command) 22 void Add(CommandMap& commands, Command* command)
(...skipping 16 matching lines...) Expand all
71 std::istringstream lineStream(commandLine); 39 std::istringstream lineStream(commandLine);
72 lineStream >> name; 40 lineStream >> name;
73 std::getline(lineStream, arguments); 41 std::getline(lineStream, arguments);
74 } 42 }
75 } 43 }
76 44
77 int main() 45 int main()
78 { 46 {
79 try 47 try
80 { 48 {
81 LibFileSystem fileSystem; 49 AdblockPlus::DefaultFileSystem fileSystem;
82 AdblockPlus::DefaultWebRequest webRequest; 50 AdblockPlus::DefaultWebRequest webRequest;
83 CerrErrorCallback errorCallback; 51 CerrErrorCallback errorCallback;
84 AdblockPlus::JsEngine jsEngine(&fileSystem, &webRequest, &errorCallback); 52 AdblockPlus::JsEngine jsEngine(&fileSystem, &webRequest, &errorCallback);
85 AdblockPlus::FilterEngine filterEngine(jsEngine); 53 AdblockPlus::FilterEngine filterEngine(jsEngine);
86 54
87 CommandMap commands; 55 CommandMap commands;
88 Add(commands, new GcCommand(jsEngine)); 56 Add(commands, new GcCommand(jsEngine));
89 Add(commands, new HelpCommand(commands)); 57 Add(commands, new HelpCommand(commands));
90 Add(commands, new FiltersCommand(filterEngine)); 58 Add(commands, new FiltersCommand(filterEngine));
91 Add(commands, new SubscriptionsCommand(filterEngine)); 59 Add(commands, new SubscriptionsCommand(filterEngine));
(...skipping 18 matching lines...) Expand all
110 std::cout << error.what() << std::endl; 78 std::cout << error.what() << std::endl;
111 } 79 }
112 } 80 }
113 } 81 }
114 catch (const std::exception& e) 82 catch (const std::exception& e)
115 { 83 {
116 std::cerr << "Exception: " << e.what() << std::endl; 84 std::cerr << "Exception: " << e.what() << std::endl;
117 } 85 }
118 return 0; 86 return 0;
119 } 87 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld