Skip to content

Commit

Permalink
Deprecate scoped_ptr part 2.
Browse files Browse the repository at this point in the history
With this CL, scoped_ptr is replaced with std::unique_ptr mainly in the
following directories.
 - src/dictionary/file/
 - src/gui/
 - src/server/
 - src/storage/

BUG=#219
TEST=unittest
REF_BUG=9164610
REF_CL=84944931,84944947,84945576,85032863,85033860
  • Loading branch information
Noriyuki Takahashi authored and yukawa committed Oct 25, 2015
1 parent d56d5db commit b3330bb
Show file tree
Hide file tree
Showing 40 changed files with 177 additions and 113 deletions.
9 changes: 4 additions & 5 deletions src/dictionary/file/codec_test.cc
Expand Up @@ -29,18 +29,17 @@

#include "dictionary/file/codec.h"

#include <memory>

#include "base/file_stream.h"
#include "base/file_util.h"
#include "base/logging.h"
#include "base/scoped_ptr.h"
#include "base/util.h"
#include "dictionary/file/codec_interface.h"
#include "dictionary/file/section.h"
#include "testing/base/public/googletest.h"
#include "testing/base/public/gunit.h"

DECLARE_string(test_tmpdir);

namespace mozc {
namespace dictionary {
namespace {
Expand Down Expand Up @@ -117,7 +116,7 @@ class CodecMock : public DictionaryFileCodecInterface {
};

TEST_F(CodecTest, FactoryTest) {
scoped_ptr<CodecMock> codec_mock(new CodecMock);
std::unique_ptr<CodecMock> codec_mock(new CodecMock);
DictionaryFileCodecFactory::SetCodec(codec_mock.get());
const DictionaryFileCodecInterface *codec =
DictionaryFileCodecFactory::GetCodec();
Expand Down Expand Up @@ -185,7 +184,7 @@ TEST_F(CodecTest, DefaultTest) {
}

TEST_F(CodecTest, CodecTest) {
scoped_ptr<DictionaryFileCodec> default_codec(
std::unique_ptr<DictionaryFileCodec> default_codec(
new DictionaryFileCodec);
DictionaryFileCodecFactory::SetCodec(default_codec.get());
const DictionaryFileCodecInterface *codec =
Expand Down
4 changes: 2 additions & 2 deletions src/dictionary/file/dictionary_file.h
Expand Up @@ -33,12 +33,12 @@
#ifndef MOZC_DICTIONARY_FILE_DICTIONARY_FILE_H_
#define MOZC_DICTIONARY_FILE_DICTIONARY_FILE_H_

#include <memory>
#include <string>
#include <vector>

#include "base/mmap.h"
#include "base/port.h"
#include "base/scoped_ptr.h"

namespace mozc {
namespace dictionary {
Expand All @@ -63,7 +63,7 @@ class DictionaryFile {

private:
// This will be nullptr if the mapping source is given as a pointer.
scoped_ptr<Mmap> mapping_;
std::unique_ptr<Mmap> mapping_;
vector<DictionaryFileSection> sections_;

DISALLOW_COPY_AND_ASSIGN(DictionaryFile);
Expand Down
5 changes: 3 additions & 2 deletions src/dictionary/text_dictionary_loader.cc
Expand Up @@ -35,6 +35,7 @@

#include <algorithm>
#include <limits>
#include <memory>
#include <string>
#include <vector>

Expand Down Expand Up @@ -273,7 +274,7 @@ void TextDictionaryLoader::LoadReadingCorrectionTokens(
// We here assume that the wrong reading appear with 1/100 probability
// of the original (correct) reading.
const int kCostPenalty = 2302; // -log(1/100) * 500;
scoped_ptr<Token> token(new Token);
std::unique_ptr<Token> token(new Token);
value_key.second.CopyToString(&token->key);
token->value = max_cost_token->value;
token->lid = max_cost_token->lid;
Expand Down Expand Up @@ -314,7 +315,7 @@ Token *TextDictionaryLoader::ParseTSV(
const vector<StringPiece> &columns) const {
CHECK_LE(5, columns.size()) << "Lack of columns: " << columns.size();

scoped_ptr<Token> token(new Token);
std::unique_ptr<Token> token(new Token);

// Parse key, lid, rid, cost, value.
Util::NormalizeVoicedSoundMark(columns[0], &token->key);
Expand Down
7 changes: 4 additions & 3 deletions src/gui/about_dialog/about_dialog.h
Expand Up @@ -34,8 +34,9 @@

#include <QtGui/QDialog>

#include <memory>

#include "base/port.h"
#include "base/scoped_ptr.h"
#include "gui/about_dialog/ui_about_dialog.h"

class QImage;
Expand All @@ -53,7 +54,7 @@ class AboutDialog : public QDialog,
private Ui::AboutDialog {
Q_OBJECT;
public:
explicit AboutDialog(QWidget *parent = NULL);
explicit AboutDialog(QWidget *parent = nullptr);
void SetLinkCallback(LinkCallbackInterface *callback);

void paintEvent(QPaintEvent *event);
Expand All @@ -63,7 +64,7 @@ class AboutDialog : public QDialog,

private:
LinkCallbackInterface *callback_;
scoped_ptr<QImage> product_image_;
std::unique_ptr<QImage> product_image_;
};

} // namespace mozc::gui
Expand Down
6 changes: 4 additions & 2 deletions src/gui/base/setup_util.h
Expand Up @@ -30,8 +30,9 @@
#ifndef MOZC_GUI_BASE_SETUP_UTIL_H_
#define MOZC_GUI_BASE_SETUP_UTIL_H_

#include <memory>

#include "base/port.h"
#include "base/scoped_ptr.h"

namespace mozc {

Expand Down Expand Up @@ -72,12 +73,13 @@ class SetupUtil {
// Imports MS-IME's user dictionary to Mozc' dictionary
bool MigrateDictionaryFromMSIME();

scoped_ptr<UserDictionaryStorage> storage_;
std::unique_ptr<UserDictionaryStorage> storage_;

bool is_userdictionary_locked_;

DISALLOW_COPY_AND_ASSIGN(SetupUtil);
};

} // namespace gui
} // namespace mozc

Expand Down
5 changes: 3 additions & 2 deletions src/gui/base/singleton_window_helper.h
Expand Up @@ -44,10 +44,10 @@
#ifndef MOZC_GUI_BASE_SINGLETON_WINDOW_HELPER_H_
#define MOZC_GUI_BASE_SINGLETON_WINDOW_HELPER_H_

#include <memory>
#include <string>

#include "base/port.h"
#include "base/scoped_ptr.h"

namespace mozc {
class ProcessMutex;
Expand All @@ -66,10 +66,11 @@ class SingletonWindowHelper {
bool ActivatePreviousWindow();

private:
scoped_ptr<ProcessMutex> mutex_;
std::unique_ptr<ProcessMutex> mutex_;

DISALLOW_COPY_AND_ASSIGN(SingletonWindowHelper);
};

} // namespace gui
} // namespace mozc

Expand Down
6 changes: 5 additions & 1 deletion src/gui/character_pad/character_pad_libmain.cc
Expand Up @@ -33,6 +33,9 @@

#include <QtGui/QApplication>
#include <QtCore/QFile>

#include <memory>

#include "base/logging.h"
#include "base/system_util.h"
#include "base/util.h"
Expand All @@ -59,6 +62,7 @@ enum {
CHARACTER_PALETTE,
HAND_WRITING
};

} // namespace

int RunCharacterPad(int argc, char *argv[],
Expand All @@ -70,7 +74,7 @@ int RunCharacterPad(int argc, char *argv[],

mozc::gui::LocaleUtil::InstallTranslationMessageAndFont("character_pad");

scoped_ptr<QMainWindow> window;
std::unique_ptr<QMainWindow> window;

if (mode == HAND_WRITING) {
window.reset(new mozc::gui::HandWriting);
Expand Down
6 changes: 4 additions & 2 deletions src/gui/character_pad/character_palette.h
Expand Up @@ -32,8 +32,10 @@

#include <QtCore/QMap>
#include <QtGui/QMainWindow>

#include <memory>

#include "base/port.h"
#include "base/scoped_ptr.h"
#include "gui/character_pad/ui_character_palette.h"

class QTextCodec;
Expand Down Expand Up @@ -86,7 +88,7 @@ class CharacterPalette : public QMainWindow,
bool winEvent(MSG *message, long *result);
#endif // OS_WIN

scoped_ptr<client::ClientInterface> client_;
std::unique_ptr<client::ClientInterface> client_;
bool usage_stats_enabled_;

private:
Expand Down
9 changes: 5 additions & 4 deletions src/gui/character_pad/hand_writing.h
Expand Up @@ -32,7 +32,8 @@

#include <QtGui/QMainWindow>

#include "base/scoped_ptr.h"
#include <memory>

#include "gui/character_pad/ui_hand_writing.h"

namespace mozc {
Expand Down Expand Up @@ -71,7 +72,7 @@ class HandWriting : public QMainWindow,

void updateHandwritingSource(int index);

scoped_ptr<client::ClientInterface> client_;
std::unique_ptr<client::ClientInterface> client_;
bool usage_stats_enabled_;
// Do not depend on CloudHandwriting class to keep dependencies
// minimum.
Expand All @@ -84,9 +85,9 @@ class HandWriting : public QMainWindow,
// necessary and updates the current config as
// |config.set_allow_cloud_handwriting(true)| when it is allowed.
bool TryToEnableCloudHandwriting();
scoped_ptr<mozc::handwriting::HandwritingInterface> cloud_handwriting_;
std::unique_ptr<mozc::handwriting::HandwritingInterface> cloud_handwriting_;
#endif // ENABLE_CLOUD_HANDWRITING
scoped_ptr<mozc::handwriting::HandwritingInterface> zinnia_handwriting_;
std::unique_ptr<mozc::handwriting::HandwritingInterface> zinnia_handwriting_;
};
} // namespace gui
} // namespace mozc
Expand Down
8 changes: 6 additions & 2 deletions src/gui/config_dialog/character_form_editor.cc
Expand Up @@ -27,9 +27,13 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "gui/config_dialog/character_form_editor.h"

#include <QtGui/QtGui>

#include <memory>

#include "config/config_handler.h"
#include "gui/config_dialog/character_form_editor.h"
#include "gui/config_dialog/combobox_delegate.h"

namespace mozc {
Expand Down Expand Up @@ -117,7 +121,7 @@ void CharacterFormEditor::Load(const config::Config &config) {
header << tr("Group") << tr("Composition") << tr("Conversion");
setHorizontalHeaderLabels(header);

scoped_ptr<config::Config> default_config;
std::unique_ptr<config::Config> default_config;
const config::Config *target_config = &config;

// make sure that table isn't empty.
Expand Down
11 changes: 7 additions & 4 deletions src/gui/config_dialog/character_form_editor.h
Expand Up @@ -31,8 +31,10 @@
#define MOZC_GUI_CONFIG_DIALOG_CHARACTER_FORM_EDITOR_H_

#include <QtGui/QTableWidget>

#include <memory>

#include "base/port.h"
#include "base/scoped_ptr.h"
#include "protocol/config.pb.h"

namespace mozc {
Expand All @@ -54,10 +56,11 @@ class CharacterFormEditor : public QTableWidget {
void Save(config::Config *config);

private:
scoped_ptr<ComboBoxDelegate> delegate_;
std::unique_ptr<ComboBoxDelegate> delegate_;
};
} // gui
} // mozc

} // namespace gui
} // namespace mozc

#if defined UI_CONFIG_DIALOG_H
using mozc::gui::CharacterFormEditor;
Expand Down
5 changes: 4 additions & 1 deletion src/gui/config_dialog/config_dialog.cc
Expand Up @@ -36,9 +36,12 @@
#endif

#include <QtGui/QMessageBox>

#include <algorithm>
#include <cstdlib>
#include <memory>
#include <sstream>

#include "base/config_file_stream.h"
#include "base/const.h"
#include "base/logging.h"
Expand Down Expand Up @@ -815,7 +818,7 @@ void ConfigDialog::EditKeymap() {
// Load from predefined mapping file.
const char *keymap_file =
keymap::KeyMapManager::GetKeyMapFileName(itr->second);
scoped_ptr<istream> ifs(
std::unique_ptr<istream> ifs(
ConfigFileStream::LegacyOpen(keymap_file));
CHECK(ifs.get() != NULL); // should never happen
stringstream buffer;
Expand Down
6 changes: 4 additions & 2 deletions src/gui/config_dialog/config_dialog.h
Expand Up @@ -34,10 +34,12 @@

#include <QtCore/QObject>
#include <QtCore/QTimer>

#include <map>
#include <memory>
#include <string>

#include "base/port.h"
#include "base/scoped_ptr.h"
#include "gui/config_dialog/ui_config_dialog.h"
#include "protocol/config.pb.h"

Expand Down Expand Up @@ -100,7 +102,7 @@ class ConfigDialog : public QDialog,
bool Update();
void Reload();

scoped_ptr<client::ClientInterface> client_;
std::unique_ptr<client::ClientInterface> client_;
string custom_keymap_table_;
string custom_roman_table_;
config::Config::InformationListConfig information_list_config_;
Expand Down
10 changes: 7 additions & 3 deletions src/gui/config_dialog/keybinding_editor.h
Expand Up @@ -32,9 +32,11 @@

#include <QtGui/QtGui>
#include <QtGui/QDialog>

#include <memory>
#include <string>

#include "base/port.h"
#include "base/scoped_ptr.h"
#include "gui/config_dialog/ui_keybinding_editor.h"

namespace mozc {
Expand Down Expand Up @@ -75,8 +77,10 @@ class KeyBindingEditor : public QDialog,

private:
QWidget *trigger_parent_;
scoped_ptr<KeyBindingFilter> filter_;
std::unique_ptr<KeyBindingFilter> filter_;
};
} // namespace mozc::gui

} // namespace gui
} // namespace mozc

#endif // MOZC_GUI_CONFIG_DIALOG_KEYBINDING_EDITOR_H_
4 changes: 3 additions & 1 deletion src/gui/config_dialog/keybinding_editor_delegate.cc
Expand Up @@ -32,6 +32,8 @@
#include <QtGui/QtGui>
#include <QtGui/QPushButton>

#include <memory>

#include "base/logging.h"
#include "gui/config_dialog/keybinding_editor.h"

Expand All @@ -55,7 +57,7 @@ class KeyBindingEditorTriggerButton : public QPushButton {
}

private:
scoped_ptr<KeyBindingEditor> editor_;
std::unique_ptr<KeyBindingEditor> editor_;
};

KeyBindingEditorDelegate::KeyBindingEditorDelegate(QObject *parent)
Expand Down

0 comments on commit b3330bb

Please sign in to comment.