Skip to content

Commit

Permalink
Convert to the "standard" C++ coding style (class members)
Browse files Browse the repository at this point in the history
Convert step by step the coding style to the "standard" C++ coding style.
  • Loading branch information
vbaderks committed Jul 11, 2020
1 parent 2f60150 commit cf59826
Show file tree
Hide file tree
Showing 47 changed files with 660 additions and 665 deletions.
3 changes: 2 additions & 1 deletion CharLS.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseAuto/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CppNaming/Rules/=Classes_0020and_0020structs/@EntryIndexedValue">&lt;NamingElement Priority="1"&gt;&lt;Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"&gt;&lt;type Name="__interface" /&gt;&lt;type Name="class" /&gt;&lt;type Name="struct" /&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aa_bb" /&gt;&lt;/NamingElement&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CppNaming/Rules/=Class_0020and_0020struct_0020fields/@EntryIndexedValue">&lt;NamingElement Priority="10"&gt;&lt;Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"&gt;&lt;type Name="class field" /&gt;&lt;type Name="struct field" /&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="False" Prefix="" Suffix="_" Style="aa_bb" /&gt;&lt;/NamingElement&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CppNaming/Rules/=Class_0020and_0020struct_0020methods/@EntryIndexedValue">&lt;NamingElement Priority="9"&gt;&lt;Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"&gt;&lt;type Name="member function" /&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="False" Prefix="" Suffix="" Style="aa_bb" /&gt;&lt;/NamingElement&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CppNaming/Rules/=Class_0020and_0020struct_0020methods/@EntryIndexedValue">&lt;NamingElement Priority="9"&gt;&lt;Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"&gt;&lt;type Name="member function" /&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aa_bb" /&gt;&lt;/NamingElement&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CppNaming/Rules/=Class_0020and_0020struct_0020public_0020fields/@EntryIndexedValue">&lt;NamingElement Priority="11"&gt;&lt;Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="PUBLIC"&gt;&lt;type Name="class field" /&gt;&lt;type Name="struct field" /&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="False" Prefix="" Suffix="" Style="aa_bb" /&gt;&lt;/NamingElement&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CppNaming/Rules/=Enums/@EntryIndexedValue">&lt;NamingElement Priority="2"&gt;&lt;Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"&gt;&lt;type Name="enum" /&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="False" Prefix="" Suffix="" Style="aa_bb" /&gt;&lt;/NamingElement&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CppNaming/Rules/=Enum_0020members/@EntryIndexedValue">&lt;NamingElement Priority="13"&gt;&lt;Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"&gt;&lt;type Name="enumerator" /&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="False" Prefix="" Suffix="" Style="aa_bb" /&gt;&lt;/NamingElement&gt;</s:String>
Expand All @@ -48,6 +48,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=cpixel/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=cppcoreguidelines/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=decodetest/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=dequantize/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=destructors/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Dicom/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Dtor/@EntryIndexedValue">True</s:Boolean>
Expand Down
12 changes: 6 additions & 6 deletions src/charls_jpegls_encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ struct charls_jpegls_encoder final
writer_.write_start_of_scan_segment(1, near_lossless_, interleave_mode_);
encode_scan(sourceInfo, stride, 1);

// Synchronize the source stream (EncodeScan works on a local copy)
// Synchronize the source stream (encode_scan works on a local copy)
skip_bytes(sourceInfo, byteCountComponent);
}
}
Expand Down Expand Up @@ -226,14 +226,14 @@ struct charls_jpegls_encoder final
{
const charls::frame_info frame_info{frame_info_.width, frame_info_.height, frame_info_.bits_per_sample, component_count};

auto codec = jls_codec_factory<encoder_strategy>().CreateCodec(frame_info,
auto codec = jls_codec_factory<encoder_strategy>().create_codec(frame_info,
{near_lossless_, interleave_mode_, color_transformation_, false},
preset_coding_parameters_);
unique_ptr<process_line> processLine(codec->CreateProcess(source, stride));
byte_stream_info destination{writer_.OutputStream()};
const size_t bytesWritten = codec->EncodeScan(move(processLine), destination);
unique_ptr<process_line> processLine(codec->create_process(source, stride));
byte_stream_info destination{writer_.output_stream()};
const size_t bytesWritten = codec->encode_scan(move(processLine), destination);

// Synchronize the destination encapsulated in the writer (EncodeScan works on a local copy)
// Synchronize the destination encapsulated in the writer (encode_scan works on a local copy)
writer_.seek(bytesWritten);
}

Expand Down
6 changes: 3 additions & 3 deletions src/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ struct jls_context final
{
}

FORCE_INLINE int32_t GetErrorCorrection(const int32_t k) const noexcept
FORCE_INLINE int32_t get_error_correction(const int32_t k) const noexcept
{
if (k != 0)
return 0;

return BitWiseSign(2 * B + N - 1);
}

FORCE_INLINE void UpdateVariables(const int32_t error_value, const int32_t near_lossless, const int32_t NRESET) noexcept
FORCE_INLINE void update_variables(const int32_t error_value, const int32_t near_lossless, const int32_t NRESET) noexcept
{
ASSERT(N != 0);

Expand Down Expand Up @@ -79,7 +79,7 @@ struct jls_context final
ASSERT(N != 0);
}

FORCE_INLINE int32_t GetGolomb() const noexcept
FORCE_INLINE int32_t get_golomb_code() const noexcept
{
const int32_t nTest = N;
const int32_t aTest = A;
Expand Down
14 changes: 7 additions & 7 deletions src/context_run_mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct context_run_mode final
{
}

FORCE_INLINE int32_t GetGolomb() const noexcept
FORCE_INLINE int32_t get_golomb_code() const noexcept
{
const int32_t TEMP = A + (N >> 1) * nRItype_;
int32_t nTest = N;
Expand All @@ -44,7 +44,7 @@ struct context_run_mode final
return k;
}

void UpdateVariables(const int32_t error_value, const int32_t EMErrval) noexcept
void update_variables(const int32_t error_value, const int32_t EMErrval) noexcept
{
if (error_value < 0)
{
Expand All @@ -60,22 +60,22 @@ struct context_run_mode final
N = N + 1;
}

FORCE_INLINE int32_t ComputeErrVal(const int32_t temp, const int32_t k) const noexcept
FORCE_INLINE int32_t compute_error_value(const int32_t temp, const int32_t k) const noexcept
{
const bool map = temp & 1;
const int32_t errorValueAbs = (temp + static_cast<int32_t>(map)) / 2;

if ((k != 0 || (2 * Nn >= N)) == map)
{
ASSERT(map == ComputeMap(-errorValueAbs, k));
ASSERT(map == compute_map(-errorValueAbs, k));
return -errorValueAbs;
}

ASSERT(map == ComputeMap(errorValueAbs, k));
ASSERT(map == compute_map(errorValueAbs, k));
return errorValueAbs;
}

bool ComputeMap(const int32_t error_value, const int32_t k) const noexcept
bool compute_map(const int32_t error_value, const int32_t k) const noexcept
{
if (k == 0 && error_value > 0 && 2 * Nn < N)
return true;
Expand All @@ -89,7 +89,7 @@ struct context_run_mode final
return false;
}

FORCE_INLINE bool ComputeMapNegativeE(const int32_t k) const noexcept
FORCE_INLINE bool compute_map_negative_e(const int32_t k) const noexcept
{
return k != 0 || 2 * Nn >= N;
}
Expand Down
78 changes: 39 additions & 39 deletions src/decoder_strategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ class decoder_strategy
decoder_strategy& operator=(const decoder_strategy&) = delete;
decoder_strategy& operator=(decoder_strategy&&) = delete;

virtual std::unique_ptr<process_line> CreateProcess(byte_stream_info raw_stream_info, uint32_t stride) = 0;
virtual void SetPresets(const jpegls_pc_parameters& preset_coding_parameters) = 0;
virtual void DecodeScan(std::unique_ptr<process_line> output_data, const JlsRect& size, byte_stream_info& compressed_data) = 0;
virtual std::unique_ptr<process_line> create_process(byte_stream_info raw_stream_info, uint32_t stride) = 0;
virtual void set_presets(const jpegls_pc_parameters& preset_coding_parameters) = 0;
virtual void decode_scan(std::unique_ptr<process_line> output_data, const JlsRect& size, byte_stream_info& compressed_data) = 0;

void Init(byte_stream_info& compressed_stream)
void initialize(byte_stream_info& compressed_stream)
{
validBits_ = 0;
readCache_ = 0;
Expand All @@ -46,7 +46,7 @@ class decoder_strategy
position_ = buffer_.data();
endPosition_ = position_;
byteStream_ = compressed_stream.rawStream;
AddBytesFromStream();
add_bytes_from_stream();
}
else
{
Expand All @@ -55,11 +55,11 @@ class decoder_strategy
endPosition_ = position_ + compressed_stream.count;
}

nextFFPosition_ = FindNextFF();
MakeValid();
nextFFPosition_ = find_next_ff();
make_valid();
}

void AddBytesFromStream()
void add_bytes_from_stream()
{
if (!byteStream_ || byteStream_->sgetc() == std::char_traits<char>::eof())
return;
Expand All @@ -84,26 +84,26 @@ class decoder_strategy
endPosition_ += readBytes;
}

FORCE_INLINE void Skip(const int32_t length) noexcept
FORCE_INLINE void skip(const int32_t length) noexcept
{
validBits_ -= length;
readCache_ = readCache_ << length;
}

static void OnLineBegin(const size_t /*pixel_count*/, void* /*ptypeBuffer*/, int32_t /*pixelStride*/) noexcept
static void on_line_begin(const size_t /*pixel_count*/, void* /*ptypeBuffer*/, int32_t /*pixelStride*/) noexcept
{
}

void OnLineEnd(const size_t pixel_count, const void* source, const int32_t pixel_stride) const
void on_line_end(const size_t pixel_count, const void* source, const int32_t pixel_stride) const
{
processLine_->NewLineDecoded(source, pixel_count, pixel_stride);
processLine_->new_line_decoded(source, pixel_count, pixel_stride);
}

void EndScan()
void end_scan()
{
if (*position_ != JpegMarkerStartByte)
{
ReadBit();
read_bit();

if (*position_ != JpegMarkerStartByte)
impl::throw_jpegls_error(jpegls_errc::too_much_encoded_data);
Expand All @@ -113,7 +113,7 @@ class decoder_strategy
impl::throw_jpegls_error(jpegls_errc::too_much_encoded_data);
}

FORCE_INLINE bool OptimizedRead() noexcept
FORCE_INLINE bool optimized_read() noexcept
{
// Easy & fast: if there is no 0xFF byte in sight, we can read without bit stuffing
if (position_ < nextFFPosition_ - (sizeof(bufType) - 1))
Expand All @@ -128,14 +128,14 @@ class decoder_strategy
return false;
}

void MakeValid()
void make_valid()
{
ASSERT(validBits_ <= bufType_bit_count - 8);

if (OptimizedRead())
if (optimized_read())
return;

AddBytesFromStream();
add_bytes_from_stream();

do
{
Expand Down Expand Up @@ -171,10 +171,10 @@ class decoder_strategy
}
} while (validBits_ < bufType_bit_count - 8);

nextFFPosition_ = FindNextFF();
nextFFPosition_ = find_next_ff();
}

uint8_t* FindNextFF() const noexcept
uint8_t* find_next_ff() const noexcept
{
auto* positionNextFF = position_;

Expand All @@ -189,7 +189,7 @@ class decoder_strategy
return positionNextFF;
}

uint8_t* GetCurBytePos() const noexcept
uint8_t* get_cur_byte_pos() const noexcept
{
int32_t validBits = validBits_;
uint8_t* compressedBytes = position_;
Expand All @@ -206,49 +206,49 @@ class decoder_strategy
}
}

FORCE_INLINE int32_t ReadValue(const int32_t length)
FORCE_INLINE int32_t read_value(const int32_t length)
{
if (validBits_ < length)
{
MakeValid();
make_valid();
if (validBits_ < length)
impl::throw_jpegls_error(jpegls_errc::invalid_encoded_data);
}

ASSERT(length != 0 && length <= validBits_);
ASSERT(length < 32);
const auto result = static_cast<int32_t>(readCache_ >> (bufType_bit_count - length));
Skip(length);
skip(length);
return result;
}

FORCE_INLINE int32_t PeekByte()
FORCE_INLINE int32_t peek_byte()
{
if (validBits_ < 8)
{
MakeValid();
make_valid();
}

return static_cast<int32_t>(readCache_ >> (bufType_bit_count - 8));
}

FORCE_INLINE bool ReadBit()
FORCE_INLINE bool read_bit()
{
if (validBits_ <= 0)
{
MakeValid();
make_valid();
}

const bool bSet = (readCache_ & (static_cast<bufType>(1) << (bufType_bit_count - 1))) != 0;
Skip(1);
skip(1);
return bSet;
}

FORCE_INLINE int32_t Peek0Bits()
FORCE_INLINE int32_t peek_0_bits()
{
if (validBits_ < 16)
{
MakeValid();
make_valid();
}
bufType valTest = readCache_;

Expand All @@ -262,29 +262,29 @@ class decoder_strategy
return -1;
}

FORCE_INLINE int32_t ReadHighBits()
FORCE_INLINE int32_t read_high_bits()
{
const int32_t count = Peek0Bits();
const int32_t count = peek_0_bits();
if (count >= 0)
{
Skip(count + 1);
skip(count + 1);
return count;
}
Skip(15);
skip(15);

for (int32_t highBitsCount = 15;; ++highBitsCount)
{
if (ReadBit())
if (read_bit())
return highBitsCount;
}
}

int32_t ReadLongValue(const int32_t length)
int32_t read_long_value(const int32_t length)
{
if (length <= 24)
return ReadValue(length);
return read_value(length);

return (ReadValue(length - 24) << 24) + ReadValue(24);
return (read_value(length - 24) << 24) + read_value(24);
}

protected:
Expand Down
Loading

0 comments on commit cf59826

Please sign in to comment.