Browse Source

DownloadEngine: Use std::unique_ptr for checkIntegrityMan_, fileAllocationMan_

Tatsuhiro Tsujikawa 12 years ago
parent
commit
697c1008f7

+ 1 - 1
src/CheckIntegrityDispatcherCommand.cc

@@ -45,7 +45,7 @@ namespace aria2 {
 
 CheckIntegrityDispatcherCommand::CheckIntegrityDispatcherCommand
 (cuid_t cuid,
- const std::shared_ptr<CheckIntegrityMan>& fileAllocMan,
+ CheckIntegrityMan* fileAllocMan,
  DownloadEngine* e)
   : SequentialDispatcherCommand<CheckIntegrityEntry>{cuid, fileAllocMan, e}
 {

+ 1 - 1
src/CheckIntegrityDispatcherCommand.h

@@ -47,7 +47,7 @@ class CheckIntegrityDispatcherCommand :
 public:
   CheckIntegrityDispatcherCommand
   (cuid_t cuid,
-   const std::shared_ptr<CheckIntegrityMan>& checkMan,
+   CheckIntegrityMan* checkMan,
    DownloadEngine* e);
 protected:
   virtual std::unique_ptr<Command> createCommand(CheckIntegrityEntry* entry);

+ 4 - 4
src/DownloadEngine.cc

@@ -585,15 +585,15 @@ void DownloadEngine::setRequestGroupMan
 }
 
 void DownloadEngine::setFileAllocationMan
-(const std::shared_ptr<FileAllocationMan>& faman)
+(std::unique_ptr<FileAllocationMan> faman)
 {
-  fileAllocationMan_ = faman;
+  fileAllocationMan_ = std::move(faman);
 }
 
 void DownloadEngine::setCheckIntegrityMan
-(const std::shared_ptr<CheckIntegrityMan>& ciman)
+(std::unique_ptr<CheckIntegrityMan> ciman)
 {
-  checkIntegrityMan_ = ciman;
+  checkIntegrityMan_ = std::move(ciman);
 }
 
 #ifdef HAVE_ARES_ADDR_NODE

+ 6 - 6
src/DownloadEngine.h

@@ -169,8 +169,8 @@ private:
 
   std::deque<std::unique_ptr<Command>> commands_;
   std::shared_ptr<RequestGroupMan> requestGroupMan_;
-  std::shared_ptr<FileAllocationMan> fileAllocationMan_;
-  std::shared_ptr<CheckIntegrityMan> checkIntegrityMan_;
+  std::unique_ptr<FileAllocationMan> fileAllocationMan_;
+  std::unique_ptr<CheckIntegrityMan> checkIntegrityMan_;
   Option* option_;
 public:
   DownloadEngine(const std::shared_ptr<EventPoll>& eventPoll);
@@ -211,19 +211,19 @@ public:
 
   void setRequestGroupMan(const std::shared_ptr<RequestGroupMan>& rgman);
 
-  const std::shared_ptr<FileAllocationMan>& getFileAllocationMan() const
+  const std::unique_ptr<FileAllocationMan>& getFileAllocationMan() const
   {
     return fileAllocationMan_;
   }
 
-  void setFileAllocationMan(const std::shared_ptr<FileAllocationMan>& faman);
+  void setFileAllocationMan(std::unique_ptr<FileAllocationMan> faman);
 
-  const std::shared_ptr<CheckIntegrityMan>& getCheckIntegrityMan() const
+  const std::unique_ptr<CheckIntegrityMan>& getCheckIntegrityMan() const
   {
     return checkIntegrityMan_;
   }
 
-  void setCheckIntegrityMan(const std::shared_ptr<CheckIntegrityMan>& ciman);
+  void setCheckIntegrityMan(std::unique_ptr<CheckIntegrityMan> ciman);
 
   Option* getOption() const
   {

+ 6 - 6
src/DownloadEngineFactory.cc

@@ -153,19 +153,19 @@ DownloadEngineFactory::newDownloadEngine
     (std::move(requestGroups), MAX_CONCURRENT_DOWNLOADS, op);
   requestGroupMan->initWrDiskCache();
   e->setRequestGroupMan(requestGroupMan);
-  e->setFileAllocationMan
-    (std::shared_ptr<FileAllocationMan>(new FileAllocationMan()));
+  e->setFileAllocationMan(make_unique<FileAllocationMan>());
 #ifdef ENABLE_MESSAGE_DIGEST
-  e->setCheckIntegrityMan
-    (std::shared_ptr<CheckIntegrityMan>(new CheckIntegrityMan()));
+  e->setCheckIntegrityMan(make_unique<CheckIntegrityMan>());
 #endif // ENABLE_MESSAGE_DIGEST
   e->addRoutineCommand(make_unique<FillRequestGroupCommand>
                        (e->newCUID(), e.get()));
   e->addRoutineCommand(make_unique<FileAllocationDispatcherCommand>
-                       (e->newCUID(), e->getFileAllocationMan(), e.get()));
+                       (e->newCUID(), e->getFileAllocationMan().get(),
+                        e.get()));
 #ifdef ENABLE_MESSAGE_DIGEST
   e->addRoutineCommand(make_unique<CheckIntegrityDispatcherCommand>
-                       (e->newCUID(), e->getCheckIntegrityMan(), e.get()));
+                       (e->newCUID(), e->getCheckIntegrityMan().get(),
+                        e.get()));
 #endif // ENABLE_MESSAGE_DIGEST
 
   if(op->getAsInt(PREF_AUTO_SAVE_INTERVAL) > 0) {

+ 1 - 1
src/FileAllocationDispatcherCommand.cc

@@ -45,7 +45,7 @@ namespace aria2 {
 
 FileAllocationDispatcherCommand::FileAllocationDispatcherCommand
 (cuid_t cuid,
- const std::shared_ptr<FileAllocationMan>& fileAllocMan,
+ FileAllocationMan* fileAllocMan,
  DownloadEngine* e)
   : SequentialDispatcherCommand<FileAllocationEntry>{cuid, fileAllocMan, e}
 {}

+ 1 - 1
src/FileAllocationDispatcherCommand.h

@@ -47,7 +47,7 @@ class FileAllocationDispatcherCommand :
 public:
   FileAllocationDispatcherCommand
   (cuid_t cuid,
-   const std::shared_ptr<FileAllocationMan>& fileAllocMan,
+   FileAllocationMan* fileAllocMan,
    DownloadEngine* e);
 protected:
   virtual std::unique_ptr<Command> createCommand(FileAllocationEntry* entry);

+ 2 - 2
src/SequentialDispatcherCommand.h

@@ -50,7 +50,7 @@ class DownloadEngine;
 template<typename T>
 class SequentialDispatcherCommand : public Command {
 private:
-  std::shared_ptr<SequentialPicker<T> > picker_;
+  SequentialPicker<T>* picker_;
 
   DownloadEngine* e_;
 protected:
@@ -61,7 +61,7 @@ protected:
 public:
   SequentialDispatcherCommand
   (cuid_t cuid,
-   const std::shared_ptr<SequentialPicker<T>>& picker,
+   SequentialPicker<T>* picker,
    DownloadEngine* e)
     : Command{cuid}, picker_{picker}, e_{e}
   {