Skip to content

Commit

Permalink
mini::buffer_ref & mini::string_ref improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
wbenny committed Dec 26, 2018
1 parent d5c8f61 commit b9af4ee
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 158 deletions.
2 changes: 1 addition & 1 deletion mini-tor.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,6 @@
<ClCompile Include="mini\net\ssl_stream.cpp" />
<ClCompile Include="mini\net\tcp_socket.cpp" />
<ClCompile Include="mini\string.cpp" />
<ClCompile Include="mini\string_ref.cpp" />
<ClCompile Include="mini\threading\event.cpp" />
<ClCompile Include="mini\threading\mutex.cpp" />
<ClCompile Include="mini\threading\thread.cpp" />
Expand Down Expand Up @@ -1500,6 +1499,7 @@
<None Include="mini\crypto\cng\rsa.inl" />
<None Include="mini\ptr.inl" />
<None Include="mini\stack_buffer.inl" />
<None Include="mini\string_ref.inl" />
<None Include="mini\threading\locked_value.inl" />
</ItemGroup>
<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions mini-tor.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,6 @@
<ClCompile Include="mini\memory.cpp">
<Filter>Source Files\mini</Filter>
</ClCompile>
<ClCompile Include="mini\string_ref.cpp">
<Filter>Source Files\mini</Filter>
</ClCompile>
<ClCompile Include="mini\tor\parsers\onion_router_descriptor_parser.cpp">
<Filter>Source Files\mini\tor\parsers</Filter>
</ClCompile>
Expand Down Expand Up @@ -739,6 +736,9 @@
<None Include="mini\collections\hashmap.inl">
<Filter>Source Files\mini\collections</Filter>
</None>
<None Include="mini\string_ref.inl">
<Filter>Source Files\mini</Filter>
</None>
</ItemGroup>
<ItemGroup>
<Natvis Include="mini\mini.natvis">
Expand Down
25 changes: 8 additions & 17 deletions mini/buffer_ref.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,11 @@ class buffer_ref
const buffer_ref& other
) = default;

constexpr buffer_ref(
buffer_ref&& other
) = default;

constexpr buffer_ref(
std::nullptr_t
);

buffer_ref(
constexpr buffer_ref(
std::initializer_list<T> values
);

Expand Down Expand Up @@ -87,21 +83,16 @@ class buffer_ref
// assign operators.
//

buffer_ref&
constexpr buffer_ref&
operator=(
const buffer_ref& other
);

buffer_ref&
operator=(
buffer_ref&& other
);

//
// swap.
//

void
constexpr void
swap(
buffer_ref& other
);
Expand All @@ -120,7 +111,7 @@ class buffer_ref
size_type index
) const;

const value_type*
constexpr const value_type*
get_buffer(
void
) const;
Expand All @@ -129,12 +120,12 @@ class buffer_ref
// iterators.
//

const_iterator
constexpr const_iterator
begin(
void
) const;

const_iterator
constexpr const_iterator
end(
void
) const;
Expand All @@ -143,12 +134,12 @@ class buffer_ref
// capacity.
//

bool
constexpr bool
is_empty(
void
) const;

size_type
constexpr size_type
get_size(
void
) const;
Expand Down
29 changes: 8 additions & 21 deletions mini/buffer_ref.inl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ constexpr buffer_ref<T>::buffer_ref(
template <
typename T
>
buffer_ref<T>::buffer_ref(
constexpr buffer_ref<T>::buffer_ref(
std::initializer_list<T> values
)
: _begin((value_type*)values.begin())
Expand Down Expand Up @@ -82,7 +82,7 @@ constexpr buffer_ref<T>::buffer_ref(
template <
typename T
>
buffer_ref<T>&
constexpr buffer_ref<T>&
buffer_ref<T>::operator=(
const buffer_ref& other
)
Expand All @@ -93,27 +93,14 @@ buffer_ref<T>::operator=(
return *this;
}

template <
typename T
>
buffer_ref<T>&
buffer_ref<T>::operator=(
buffer_ref&& other
)
{
swap(other);

return *this;
}

//
// swap.
//

template <
typename T
>
void
constexpr void
buffer_ref<T>::swap(
buffer_ref& other
)
Expand Down Expand Up @@ -151,7 +138,7 @@ buffer_ref<T>::at(
template <
typename T
>
const typename buffer_ref<T>::value_type*
constexpr const typename buffer_ref<T>::value_type*
buffer_ref<T>::get_buffer(
void
) const
Expand All @@ -167,7 +154,7 @@ template <
typename T
>
typename buffer_ref<T>::const_iterator
buffer_ref<T>::begin(
constexpr buffer_ref<T>::begin(
void
) const
{
Expand All @@ -178,7 +165,7 @@ template <
typename T
>
typename buffer_ref<T>::const_iterator
buffer_ref<T>::end(
constexpr buffer_ref<T>::end(
void
) const
{
Expand All @@ -192,7 +179,7 @@ buffer_ref<T>::end(
template <
typename T
>
bool
constexpr bool
buffer_ref<T>::is_empty(
void
) const
Expand All @@ -203,7 +190,7 @@ buffer_ref<T>::is_empty(
template <
typename T
>
typename buffer_ref<T>::size_type
constexpr typename buffer_ref<T>::size_type
buffer_ref<T>::get_size(
void
) const
Expand Down
6 changes: 3 additions & 3 deletions mini/io/path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ path::get_file_name(

if (name_offset == string_ref::not_found || (name_offset + 1) >= p.get_size())
{
return string_ref::empty;
return string_ref();
}

return p.substring(name_offset + 1);
Expand Down Expand Up @@ -96,7 +96,7 @@ path::get_filename_without_extension(

if (name_offset == string_ref::not_found || (name_offset + 1) >= p.get_size())
{
return string_ref::empty;
return string_ref();
}

string_ref result = p.substring(name_offset + 1);
Expand All @@ -118,7 +118,7 @@ path::get_extension(
return file_name.substring(extension_offset);
}

return string_ref::empty;
return string_ref();
}

}
6 changes: 3 additions & 3 deletions mini/io/path.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace mini::io {
class path
{
public:
static const char directory_separator = '\\';
static const char alternative_directory_separator = '/';
static const char extension_separator = '.';
static constexpr auto directory_separator = string_ref("\\");
static constexpr auto alternative_directory_separator = string_ref("/");
static constexpr auto extension_separator = string_ref(".");

static string
combine(
Expand Down
2 changes: 1 addition & 1 deletion mini/net/detail/ssl_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class ssl_context
SECURITY_STATUS
initialize(
io::stream& sock,
const string_ref target_name = string_ref::empty
const string_ref target_name = string_ref()
);

void
Expand Down
2 changes: 1 addition & 1 deletion mini/net/ssl_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ssl_socket
{
public:
ssl_socket(
const string_ref host = string_ref::empty
const string_ref host = string_ref()
);

ssl_socket(
Expand Down
2 changes: 1 addition & 1 deletion mini/net/ssl_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ssl_stream
public:
ssl_stream(
io::stream& underlying_stream,
const string_ref target_name = string_ref::empty
const string_ref target_name = string_ref()
);

~ssl_stream(
Expand Down
4 changes: 2 additions & 2 deletions mini/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class string
using iterator = pointer;
using const_iterator = const_pointer;

static const size_type not_found = (size_type)-1;
static const size_type zero_terminated = (size_type)-1;
static constexpr size_type not_found = (size_type)-1;
static constexpr size_type zero_terminated = (size_type)-1;

//
// constructors.
Expand Down
Loading

0 comments on commit b9af4ee

Please sign in to comment.