Skip to content

Commit

Permalink
[omim] Replaced boost::optional with std::optional.
Browse files Browse the repository at this point in the history
Since C++17, optional is part of the C++ Standard Library.
  • Loading branch information
mpimenov authored and maksimandrianov committed Dec 26, 2019
1 parent f5de0be commit 01fdd7f
Show file tree
Hide file tree
Showing 114 changed files with 406 additions and 470 deletions.
7 changes: 3 additions & 4 deletions 3party/jansson/myjansson.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@

#include <cstdint>
#include <memory>
#include <optional>
#include <string>
#include <vector>

#include <boost/optional.hpp>

#include "3party/jansson/src/jansson.h"

namespace base
Expand Down Expand Up @@ -163,13 +162,13 @@ void FromJSONObject(json_t * root, std::string const & field, T & result)
}

template <typename T>
boost::optional<T> FromJSONObjectOptional(json_t const * root, char const * field)
std::optional<T> FromJSONObjectOptional(json_t const * root, char const * field)
{
auto * json = base::GetJSONOptionalField(root, field);
if (!json)
return {};

boost::optional<T> result{T{}};
std::optional<T> result{T{}};
FromJSON(json, *result);
return result;
}
Expand Down
6 changes: 4 additions & 2 deletions android/jni/com/mapswithme/maps/Framework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2000,7 +2000,7 @@ Java_com_mapswithme_maps_Framework_nativeHasMegafonCategoryBanner(JNIEnv * env,
if (!position)
return static_cast<jboolean>(false);

auto const latLon = mercator::ToLatLon(position.get());
auto const latLon = mercator::ToLatLon(*position);
return static_cast<jboolean>(ads::HasMegafonCategoryBanner(frm()->GetStorage(),
frm()->GetTopmostCountries(latLon),
languages::GetCurrentNorm()));
Expand Down Expand Up @@ -2111,7 +2111,9 @@ Java_com_mapswithme_maps_Framework_nativeGetCurrentTipIndex(JNIEnv * env, jclass
{
auto const & tipsApi = frm()->GetTipsApi();
auto const tip = tipsApi.GetTip();
return tip.is_initialized() ? static_cast<jint>(tip.get()) : kUndefinedTip;
if (!tip)
return kUndefinedTip;
return static_cast<jint>(*tip);
}

JNIEXPORT void JNICALL
Expand Down
2 changes: 1 addition & 1 deletion android/jni/com/mapswithme/maps/LightFramework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Java_com_mapswithme_maps_LightFramework_nativeGetNotification(JNIEnv * env, jcla
if (!notification)
return nullptr;

auto const & n = notification.get();
auto const & n = *notification;
// Type::UgcReview is only supported.
CHECK_EQUAL(n.GetType(), notifications::NotificationCandidate::Type::UgcReview, ());

Expand Down
7 changes: 3 additions & 4 deletions android/jni/com/mapswithme/maps/UserMarkHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ jobject CreateHotelType(JNIEnv * env, place_page::Info const & info)
static jmethodID const hotelTypeCtorId =
jni::GetConstructorID(env, hotelTypeClass, "(ILjava/lang/String;)V");

auto const tag = ftypes::IsHotelChecker::GetHotelTypeTag(info.GetHotelType().get());
return env->NewObject(hotelTypeClass, hotelTypeCtorId,
static_cast<jint>(info.GetHotelType().get()),
auto const tag = ftypes::IsHotelChecker::GetHotelTypeTag(*info.GetHotelType());
return env->NewObject(hotelTypeClass, hotelTypeCtorId, static_cast<jint>(*info.GetHotelType()),
jni::ToJavaString(env, tag));
}

Expand Down Expand Up @@ -148,7 +147,7 @@ jobject CreateMapObject(JNIEnv * env, place_page::Info const & info)
jni::TScopedLocalRef hotelType(env, CreateHotelType(env, info));
jni::TScopedLocalRef popularity(env, CreatePopularity(env, info));

int priceRate = info.GetRawApproximatePricing().get_value_or(kPriceRateUndefined);
int priceRate = info.GetRawApproximatePricing().value_or(kPriceRateUndefined);

if (info.IsBookmark())
{
Expand Down
5 changes: 2 additions & 3 deletions base/cancellable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
#include <atomic>
#include <chrono>
#include <mutex>
#include <optional>
#include <string>

#include <boost/optional.hpp>

namespace base
{
// This is a helper thread-safe class which can be mixed in
Expand Down Expand Up @@ -51,7 +50,7 @@ class Cancellable

mutable Status m_status = Status::Active;

boost::optional<std::chrono::steady_clock::time_point> m_deadline;
std::optional<std::chrono::steady_clock::time_point> m_deadline;
};

std::string DebugPrint(Cancellable::Status status);
Expand Down
10 changes: 5 additions & 5 deletions coding/csv_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ CSVReader::Rows CSVReader::ReadAll()
return file;
}

boost::optional<CSVReader::Row> CSVReader::ReadRow()
std::optional<CSVReader::Row> CSVReader::ReadRow()
{
auto const line = m_reader->ReadLine();
if (!line)
Expand All @@ -62,15 +62,15 @@ size_t CSVReader::GetCurrentLineNumber() const { return m_currentLine; }

CSVReader::IstreamWrapper::IstreamWrapper(std::istream & stream) : m_stream(stream) {}

boost::optional<std::string> CSVReader::IstreamWrapper::ReadLine()
std::optional<std::string> CSVReader::IstreamWrapper::ReadLine()
{
std::string line;
return std::getline(m_stream, line) ? line : boost::optional<std::string>();
return std::getline(m_stream, line) ? line : std::optional<std::string>();
}

CSVReader::ReaderWrapper::ReaderWrapper(Reader const & reader) : m_reader(reader) {}

boost::optional<std::string> CSVReader::ReaderWrapper::ReadLine()
std::optional<std::string> CSVReader::ReaderWrapper::ReadLine()
{
std::vector<char> line;
char ch = '\0';
Expand Down Expand Up @@ -98,7 +98,7 @@ CSVReader::DefaultReader::DefaultReader(std::string const & filename)
m_stream.exceptions(std::ios::badbit);
}

boost::optional<std::string> CSVReader::DefaultReader::ReadLine()
std::optional<std::string> CSVReader::DefaultReader::ReadLine()
{
return IstreamWrapper(m_stream).ReadLine();
}
Expand Down
15 changes: 7 additions & 8 deletions coding/csv_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@

#include <fstream>
#include <functional>
#include <optional>
#include <sstream>
#include <string>
#include <vector>

#include <boost/optional.hpp>

namespace coding
{
class CSVReader
Expand All @@ -26,7 +25,7 @@ class CSVReader
char GetDelimiter() const;

Row const & GetHeader() const;
boost::optional<Row> ReadRow();
std::optional<Row> ReadRow();
Rows ReadAll();

template <typename Fn>
Expand All @@ -45,7 +44,7 @@ class CSVReader
public:
virtual ~ReaderInterface() = default;

virtual boost::optional<std::string> ReadLine() = 0;
virtual std::optional<std::string> ReadLine() = 0;
};

class IstreamWrapper : public ReaderInterface
Expand All @@ -54,7 +53,7 @@ class CSVReader
explicit IstreamWrapper(std::istream & stream);

// ReaderInterface overrides:
boost::optional<std::string> ReadLine() override;
std::optional<std::string> ReadLine() override;

private:
std::istream & m_stream;
Expand All @@ -66,7 +65,7 @@ class CSVReader
explicit ReaderWrapper(Reader const & reader);

// ReaderInterface overrides:
boost::optional<std::string> ReadLine() override;
std::optional<std::string> ReadLine() override;

private:
size_t m_pos = 0;
Expand All @@ -79,7 +78,7 @@ class CSVReader
explicit DefaultReader(std::string const & filename);

// ReaderInterface overrides:
boost::optional<std::string> ReadLine() override;
std::optional<std::string> ReadLine() override;

private:
std::ifstream m_stream;
Expand Down Expand Up @@ -114,7 +113,7 @@ class CSVRunner

private:
CSVReader & m_reader;
boost::optional<CSVReader::Row> m_current;
std::optional<CSVReader::Row> m_current;
};

// Warning: It reads first line.
Expand Down
14 changes: 7 additions & 7 deletions drape/vulkan/vulkan_base_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ void VulkanBaseContext::ApplyFramebuffer(std::string const & framebufferLabel)

if (m_currentFramebuffer == nullptr)
{
colorFormat = m_surfaceFormat.get().format;
colorFormat = m_surfaceFormat->format;
depthFormat = VulkanFormatUnpacker::Unpack(TextureFormat::Depth);

fbData.m_packedAttachmentOperations = packedAttachmentOperations;
Expand Down Expand Up @@ -766,19 +766,19 @@ ref_ptr<VulkanStagingBuffer> VulkanBaseContext::GetDefaultStagingBuffer() const

void VulkanBaseContext::RecreateSwapchain()
{
CHECK(m_surface.is_initialized(), ());
CHECK(m_surfaceFormat.is_initialized(), ());
CHECK(m_surface.has_value(), ());
CHECK(m_surfaceFormat.has_value(), ());

DestroySwapchain();

VkSwapchainCreateInfoKHR swapchainCI = {};
swapchainCI.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
swapchainCI.pNext = nullptr;
swapchainCI.surface = m_surface.get();
swapchainCI.surface = *m_surface;
swapchainCI.minImageCount = std::min(m_surfaceCapabilities.minImageCount + 1,
m_surfaceCapabilities.maxImageCount);
swapchainCI.imageFormat = m_surfaceFormat.get().format;
swapchainCI.imageColorSpace = m_surfaceFormat.get().colorSpace;
swapchainCI.imageFormat = m_surfaceFormat->format;
swapchainCI.imageColorSpace = m_surfaceFormat->colorSpace;
swapchainCI.imageExtent = m_surfaceCapabilities.currentExtent;

swapchainCI.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Expand Down Expand Up @@ -819,7 +819,7 @@ void VulkanBaseContext::RecreateSwapchain()
swapchainImageViewCI.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
swapchainImageViewCI.image = m_swapchainImages[i];
swapchainImageViewCI.viewType = VK_IMAGE_VIEW_TYPE_2D;
swapchainImageViewCI.format = m_surfaceFormat.get().format;
swapchainImageViewCI.format = m_surfaceFormat->format;
swapchainImageViewCI.components = {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G,
VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A};
swapchainImageViewCI.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Expand Down
7 changes: 3 additions & 4 deletions drape/vulkan/vulkan_base_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
#include <vulkan_wrapper.h>
#include <vulkan/vulkan.h>

#include <boost/optional.hpp>

#include <array>
#include <atomic>
#include <cstdint>
#include <functional>
#include <map>
#include <optional>
#include <vector>

namespace dp
Expand Down Expand Up @@ -184,10 +183,10 @@ class VulkanBaseContext : public dp::GraphicsContext

ref_ptr<VulkanObjectManager> m_objectManager;
drape_ptr<VulkanPipeline> m_pipeline;
boost::optional<VkSurfaceKHR> m_surface;
std::optional<VkSurfaceKHR> m_surface;

VkSurfaceCapabilitiesKHR m_surfaceCapabilities;
boost::optional<VkSurfaceFormatKHR> m_surfaceFormat;
std::optional<VkSurfaceFormatKHR> m_surfaceFormat;

VkSwapchainKHR m_swapchain = {};
std::vector<VkImageView> m_swapchainImageViews;
Expand Down
15 changes: 8 additions & 7 deletions drape/vulkan/vulkan_memory_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ std::array<uint32_t, VulkanMemoryManager::kResourcesCount> const kDesiredSizeInB
100 * 1024 * 1024, // Image
}};

VkMemoryPropertyFlags GetMemoryPropertyFlags(VulkanMemoryManager::ResourceType resourceType,
boost::optional<VkMemoryPropertyFlags> & fallbackTypeBits)
VkMemoryPropertyFlags GetMemoryPropertyFlags(
VulkanMemoryManager::ResourceType resourceType,
std::optional<VkMemoryPropertyFlags> & fallbackTypeBits)
{
switch (resourceType)
{
Expand Down Expand Up @@ -93,8 +94,8 @@ VulkanMemoryManager::~VulkanMemoryManager()
ASSERT_EQUAL(m_totalAllocationCounter, 0, ());
}

boost::optional<uint32_t> VulkanMemoryManager::GetMemoryTypeIndex(uint32_t typeBits,
VkMemoryPropertyFlags properties) const
std::optional<uint32_t> VulkanMemoryManager::GetMemoryTypeIndex(
uint32_t typeBits, VkMemoryPropertyFlags properties) const
{
for (uint32_t i = 0; i < m_memoryProperties.memoryTypeCount; i++)
{
Expand Down Expand Up @@ -189,12 +190,12 @@ VulkanMemoryManager::AllocationPtr VulkanMemoryManager::Allocate(ResourceType re
}

// Looking for memory index by memory properties.
boost::optional<VkMemoryPropertyFlags> fallbackFlags;
std::optional<VkMemoryPropertyFlags> fallbackFlags;
auto flags = GetMemoryPropertyFlags(resourceType, fallbackFlags);
auto memoryTypeIndex = GetMemoryTypeIndex(memReqs.memoryTypeBits, flags);
if (!memoryTypeIndex && fallbackFlags)
{
flags = fallbackFlags.value();
flags = *fallbackFlags;
memoryTypeIndex = GetMemoryTypeIndex(memReqs.memoryTypeBits, flags);
}

Expand All @@ -209,7 +210,7 @@ VulkanMemoryManager::AllocationPtr VulkanMemoryManager::Allocate(ResourceType re
memAllocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
memAllocInfo.pNext = nullptr;
memAllocInfo.allocationSize = blockSize;
memAllocInfo.memoryTypeIndex = memoryTypeIndex.value();
memAllocInfo.memoryTypeIndex = *memoryTypeIndex;
IncrementTotalAllocationsCount();
CHECK_VK_CALL(vkAllocateMemory(m_device, &memAllocInfo, nullptr, &memory));
m_sizes[static_cast<size_t>(resourceType)] += blockSize;
Expand Down
9 changes: 4 additions & 5 deletions drape/vulkan/vulkan_memory_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
#include <vulkan_wrapper.h>
#include <vulkan/vulkan.h>

#include <boost/optional.hpp>

#include <array>
#include <cstdint>
#include <memory>
#include <mutex>
#include <vector>
#include <optional>
#include <unordered_map>
#include <vector>

namespace dp
{
Expand Down Expand Up @@ -81,8 +80,8 @@ class VulkanMemoryManager
VkPhysicalDeviceLimits const & GetDeviceLimits() const;

private:
boost::optional<uint32_t> GetMemoryTypeIndex(uint32_t typeBits,
VkMemoryPropertyFlags properties) const;
std::optional<uint32_t> GetMemoryTypeIndex(uint32_t typeBits,
VkMemoryPropertyFlags properties) const;
void IncrementTotalAllocationsCount();
void DecrementTotalAllocationsCount();

Expand Down
Loading

0 comments on commit 01fdd7f

Please sign in to comment.