Skip to content

Commit

Permalink
sprinkle a few const, &, and noexcept
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos-zamora committed Aug 26, 2020
1 parent 58dcf17 commit a150e15
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 24 deletions.
6 changes: 3 additions & 3 deletions src/cascadia/TerminalApp/GlobalAppSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ winrt::Windows::Foundation::Collections::IMapView<winrt::hstring, winrt::Termina
return _colorSchemes.GetView();
}

void GlobalAppSettings::DefaultProfile(const winrt::guid defaultProfile) noexcept
void GlobalAppSettings::DefaultProfile(const winrt::guid& defaultProfile) noexcept
{
_unparsedDefaultProfile.clear();
_defaultProfile = defaultProfile;
Expand Down Expand Up @@ -104,7 +104,7 @@ winrt::TerminalApp::AppKeyBindings GlobalAppSettings::GetKeybindings() const noe
// - settings: a TerminalSettings object to add global property values to.
// Return Value:
// - <none>
void GlobalAppSettings::ApplyToSettings(TerminalApp::TerminalSettings settings) const noexcept
void GlobalAppSettings::ApplyToSettings(const TerminalApp::TerminalSettings& settings) const noexcept
{
settings.KeyBindings(GetKeybindings());
settings.InitialRows(_InitialRows);
Expand Down Expand Up @@ -211,7 +211,7 @@ void GlobalAppSettings::LayerJson(const Json::Value& json)
// - scheme: the color scheme to add
// Return Value:
// - <none>
void GlobalAppSettings::AddColorScheme(winrt::TerminalApp::ColorScheme scheme)
void GlobalAppSettings::AddColorScheme(const winrt::TerminalApp::ColorScheme& scheme)
{
_colorSchemes.Insert(scheme.Name(), scheme);
}
Expand Down
6 changes: 3 additions & 3 deletions src/cascadia/TerminalApp/GlobalAppSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,22 @@ namespace winrt::TerminalApp::implementation
~GlobalAppSettings();

Windows::Foundation::Collections::IMapView<hstring, TerminalApp::ColorScheme> GetColorSchemes() noexcept;
void AddColorScheme(TerminalApp::ColorScheme scheme);
void AddColorScheme(const TerminalApp::ColorScheme& scheme);

TerminalApp::AppKeyBindings GetKeybindings() const noexcept;

static com_ptr<GlobalAppSettings> FromJson(const Json::Value& json);
void LayerJson(const Json::Value& json);

void ApplyToSettings(TerminalApp::TerminalSettings settings) const noexcept;
void ApplyToSettings(const TerminalApp::TerminalSettings& settings) const noexcept;

std::vector<::TerminalApp::SettingsLoadWarnings> GetKeybindingsWarnings() const;

Windows::Foundation::Collections::IMapView<hstring, TerminalApp::Command> GetCommands() noexcept;

// These are implemented manually to handle the string/GUID exchange
// by higher layers in the app.
void DefaultProfile(const guid defaultProfile) noexcept;
void DefaultProfile(const guid& defaultProfile) noexcept;
guid DefaultProfile() const;
hstring UnparsedDefaultProfile() const;

Expand Down
4 changes: 4 additions & 0 deletions src/cascadia/TerminalApp/GlobalAppSettings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import "TerminalSettings.idl";

namespace TerminalApp
{
// MIDL 3 allows for structs to hold nullable types
// Though IReference is a WinRT object, MIDL 3
// handles all of the ownership logic for us.
// Docs: https://docs.microsoft.com/en-us/uwp/midl-3/intro#types
struct LaunchPosition
{
Windows.Foundation.IReference<Int64> X;
Expand Down
18 changes: 9 additions & 9 deletions src/cascadia/TerminalApp/Profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Profile::Profile() :
{
}

Profile::Profile(IReference<guid> guid) :
Profile::Profile(const IReference<guid>& guid) :
_Guid(guid ? static_cast<decltype(_Guid)>(guid.Value()) : std::nullopt)
{
/* FontWeight is initialized here because the structure won't accept a uint16_t directly */
Expand Down Expand Up @@ -502,7 +502,7 @@ winrt::guid Profile::GetGuidOrGenerateForJson(const Json::Value& json) noexcept
return Profile::_GenerateGuidForProfile(name, source);
}

HorizontalAlignment Profile::BackgroundImageHorizontalAlignment() const noexcept
const HorizontalAlignment Profile::BackgroundImageHorizontalAlignment() const noexcept
{
if (_BackgroundImageAlignment.has_value())
{
Expand All @@ -520,7 +520,7 @@ void Profile::BackgroundImageHorizontalAlignment(const HorizontalAlignment& valu
std::get<HorizontalAlignment>(_BackgroundImageAlignment.value()) = value;
}

VerticalAlignment Profile::BackgroundImageVerticalAlignment() const noexcept
const VerticalAlignment Profile::BackgroundImageVerticalAlignment() const noexcept
{
if (_BackgroundImageAlignment.has_value())
{
Expand All @@ -538,34 +538,34 @@ void Profile::BackgroundImageVerticalAlignment(const VerticalAlignment& value) n
std::get<VerticalAlignment>(_BackgroundImageAlignment.value()) = value;
}

bool Profile::HasGuid() const
bool Profile::HasGuid() const noexcept
{
return _Guid.has_value();
}

winrt::guid Profile::Guid() const
winrt::guid Profile::Guid() const noexcept
{
// This can throw if we never had our guid set to a legitimate value.
THROW_HR_IF_MSG(E_FAIL, !_Guid.has_value(), "Profile._guid always expected to have a value");
return *_Guid;
}

void Profile::Guid(winrt::guid guid)
void Profile::Guid(const winrt::guid& guid) noexcept
{
_Guid = guid;
}

bool Profile::HasConnectionType() const
bool Profile::HasConnectionType() const noexcept
{
return _ConnectionType.has_value();
}

winrt::guid Profile::ConnectionType() const
winrt::guid Profile::ConnectionType() const noexcept
{
return *_ConnectionType;
}

void Profile::ConnectionType(winrt::guid conType)
void Profile::ConnectionType(const winrt::guid& conType) noexcept
{
_ConnectionType = conType;
}
18 changes: 9 additions & 9 deletions src/cascadia/TerminalApp/Profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace winrt::TerminalApp::implementation
{
public:
Profile();
Profile(Windows::Foundation::IReference<guid> guid);
Profile(const Windows::Foundation::IReference<guid>& guid);

~Profile();

Expand All @@ -61,18 +61,18 @@ namespace winrt::TerminalApp::implementation
void GenerateGuidIfNecessary() noexcept;
static guid GetGuidOrGenerateForJson(const Json::Value& json) noexcept;

bool HasGuid() const;
winrt::guid Guid() const;
void Guid(winrt::guid guid);
bool HasGuid() const noexcept;
winrt::guid Guid() const noexcept;
void Guid(const winrt::guid& guid) noexcept;

bool HasConnectionType() const;
winrt::guid ConnectionType() const;
void ConnectionType(winrt::guid conType);
bool HasConnectionType() const noexcept;
winrt::guid ConnectionType() const noexcept;
void ConnectionType(const winrt::guid& conType) noexcept;

// BackgroundImageAlignment is 1 setting saved as 2 separate values
Windows::UI::Xaml::HorizontalAlignment BackgroundImageHorizontalAlignment() const noexcept;
const Windows::UI::Xaml::HorizontalAlignment BackgroundImageHorizontalAlignment() const noexcept;
void BackgroundImageHorizontalAlignment(const Windows::UI::Xaml::HorizontalAlignment& value) noexcept;
Windows::UI::Xaml::VerticalAlignment BackgroundImageVerticalAlignment() const noexcept;
const Windows::UI::Xaml::VerticalAlignment BackgroundImageVerticalAlignment() const noexcept;
void BackgroundImageVerticalAlignment(const Windows::UI::Xaml::VerticalAlignment& value) noexcept;

GETSET_PROPERTY(hstring, Name, L"Default");
Expand Down

0 comments on commit a150e15

Please sign in to comment.