Skip to content

Commit

Permalink
rerun clang-format with 132 line width
Browse files Browse the repository at this point in the history
  • Loading branch information
spencer-lunarg committed Nov 14, 2023
1 parent 49dff33 commit 0b0625d
Show file tree
Hide file tree
Showing 14 changed files with 1,049 additions and 1,805 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ Language: Cpp
BasedOnStyle: Google
DerivePointerAlignment: false
SortIncludes: true
ColumnLimit: 132
...
403 changes: 132 additions & 271 deletions common/output_stream.cpp

Large diffs are not rendered by default.

22 changes: 9 additions & 13 deletions common/output_stream.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#ifndef SPIRV_REFLECT_OUTPUT_STREAM_H
#define SPIRV_REFLECT_OUTPUT_STREAM_H

#include "spirv_reflect.h"
#include <map>
#include <ostream>
#include <string>

#include "spirv_reflect.h"

std::string ToStringSpvSourceLanguage(SpvSourceLanguage lang);
std::string ToStringSpvExecutionModel(SpvExecutionModel model);
std::string ToStringSpvStorageClass(SpvStorageClass storage_class);
std::string ToStringSpvDim(SpvDim dim);
std::string ToStringSpvBuiltIn(const SpvReflectInterfaceVariable& variable,
bool preface);
std::string ToStringSpvBuiltIn(const SpvReflectInterfaceVariable& variable, bool preface);
std::string ToStringSpvImageFormat(SpvImageFormat fmt);

std::string ToStringGenerator(SpvReflectGenerator generator);
Expand All @@ -25,29 +25,27 @@ std::string ToStringFormat(SpvReflectFormat fmt);
std::string ToStringComponentType(const SpvReflectTypeDescription& type, uint32_t member_decoration_flags);
std::string ToStringType(SpvSourceLanguage src_lang, const SpvReflectTypeDescription& type);

//std::ostream& operator<<(std::ostream& os, const spv_reflect::ShaderModule& obj);
// std::ostream& operator<<(std::ostream& os, const spv_reflect::ShaderModule& obj);
void WriteReflection(const spv_reflect::ShaderModule& obj, bool flatten_cbuffers, std::ostream& os);

class SpvReflectToYaml {
public:
public:
// verbosity = 0: top-level tables only (module, block variables, interface variables, descriptor bindings).
// verbosity = 1: everything above, plus type description tables for all public objects.
// verbosity = 2: everything above, plus SPIRV bytecode and full type description table. HUGE.
explicit SpvReflectToYaml(const SpvReflectShaderModule& shader_module, uint32_t verbosity = 0);

friend std::ostream& operator<<(std::ostream& os, SpvReflectToYaml& to_yaml)
{
friend std::ostream& operator<<(std::ostream& os, SpvReflectToYaml& to_yaml) {
to_yaml.Write(os);
return os;
}
private:

private:
void Write(std::ostream& os);

SpvReflectToYaml(const SpvReflectToYaml&) = delete;
SpvReflectToYaml(const SpvReflectToYaml&&) = delete;
static std::string Indent(uint32_t level) {
return std::string(2*level, ' ');
}
static std::string Indent(uint32_t level) { return std::string(2 * level, ' '); }
static std::string SafeString(const char* str) { return str ? (std::string("\"") + str + "\"") : ""; }
void WriteTypeDescription(std::ostream& os, const SpvReflectTypeDescription& td, uint32_t indent_level);
void WriteBlockVariable(std::ostream& os, const SpvReflectBlockVariable& bv, uint32_t indent_level);
Expand All @@ -60,7 +58,6 @@ class SpvReflectToYaml {
void WriteDescriptorBindingTypes(std::ostream& os, const SpvReflectDescriptorBinding& db, uint32_t indent_level);
void WriteInterfaceVariableTypes(std::ostream& os, const SpvReflectInterfaceVariable& iv, uint32_t indent_level);


const SpvReflectShaderModule& sm_;
uint32_t verbosity_ = 0;
std::map<const SpvReflectTypeDescription*, uint32_t> type_description_to_index_;
Expand All @@ -69,5 +66,4 @@ class SpvReflectToYaml {
std::map<const SpvReflectInterfaceVariable*, uint32_t> interface_variable_to_index_;
};


#endif
58 changes: 18 additions & 40 deletions examples/arg_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,60 +8,47 @@ ArgParser::ArgParser() {}

ArgParser::~ArgParser() {}

ArgParser::Option* ArgParser::FindOptionByShortName(
const std::string& short_name) {
ArgParser::Option* ArgParser::FindOptionByShortName(const std::string& short_name) {
ArgParser::Option* p_option = nullptr;
auto it = std::find_if(std::begin(m_options), std::end(m_options),
[short_name](const ArgParser::Option& elem) -> bool {
return elem.short_name == short_name;
});
[short_name](const ArgParser::Option& elem) -> bool { return elem.short_name == short_name; });
if (it != std::end(m_options)) {
p_option = &(*it);
}
return p_option;
}

const ArgParser::Option* ArgParser::FindOptionByShortName(
const std::string& short_name) const {
const ArgParser::Option* ArgParser::FindOptionByShortName(const std::string& short_name) const {
const ArgParser::Option* p_option = nullptr;
auto it = std::find_if(std::begin(m_options), std::end(m_options),
[short_name](const ArgParser::Option& elem) -> bool {
return elem.short_name == short_name;
});
[short_name](const ArgParser::Option& elem) -> bool { return elem.short_name == short_name; });
if (it != std::end(m_options)) {
p_option = &(*it);
}
return p_option;
}

ArgParser::Option* ArgParser::FindOptionByLongName(
const std::string& long_name) {
ArgParser::Option* ArgParser::FindOptionByLongName(const std::string& long_name) {
ArgParser::Option* p_option = nullptr;
auto it = std::find_if(std::begin(m_options), std::end(m_options),
[long_name](const ArgParser::Option& elem) -> bool {
return elem.long_name == long_name;
});
[long_name](const ArgParser::Option& elem) -> bool { return elem.long_name == long_name; });
if (it != std::end(m_options)) {
p_option = &(*it);
}
return p_option;
}

const ArgParser::Option* ArgParser::FindOptionByLongName(
const std::string& long_name) const {
const ArgParser::Option* ArgParser::FindOptionByLongName(const std::string& long_name) const {
const ArgParser::Option* p_option = nullptr;
auto it = std::find_if(std::begin(m_options), std::end(m_options),
[long_name](const ArgParser::Option& elem) -> bool {
return elem.long_name == long_name;
});
[long_name](const ArgParser::Option& elem) -> bool { return elem.long_name == long_name; });
if (it != std::end(m_options)) {
p_option = &(*it);
}
return p_option;
}

bool ArgParser::AddFlag(const std::string& short_name,
const std::string& long_name, const std::string& desc) {
bool ArgParser::AddFlag(const std::string& short_name, const std::string& long_name, const std::string& desc) {
Option option = {};
option.short_name = short_name;
option.long_name = long_name;
Expand All @@ -76,9 +63,7 @@ bool ArgParser::AddFlag(const std::string& short_name,
return true;
}

bool ArgParser::AddOptionString(const std::string& short_name,
const std::string& long_name,
const std::string& desc,
bool ArgParser::AddOptionString(const std::string& short_name, const std::string& long_name, const std::string& desc,
const std::string& default_value) {
Option option = {};
option.short_name = short_name;
Expand All @@ -95,9 +80,8 @@ bool ArgParser::AddOptionString(const std::string& short_name,
return true;
}

bool ArgParser::AddOptionInt(const std::string& short_name,
const std::string& long_name,
const std::string& desc, int default_value) {
bool ArgParser::AddOptionInt(const std::string& short_name, const std::string& long_name, const std::string& desc,
int default_value) {
Option option = {};
option.short_name = short_name;
option.long_name = long_name;
Expand All @@ -113,9 +97,8 @@ bool ArgParser::AddOptionInt(const std::string& short_name,
return true;
}

bool ArgParser::AddOptionFloat(const std::string& short_name,
const std::string& long_name,
const std::string& desc, float default_value) {
bool ArgParser::AddOptionFloat(const std::string& short_name, const std::string& long_name, const std::string& desc,
float default_value) {
Option option = {};
option.short_name = short_name;
option.long_name = long_name;
Expand Down Expand Up @@ -228,8 +211,7 @@ bool ArgParser::GetArg(size_t i, std::string* p_value) const {

const std::vector<std::string>& ArgParser::GetArgs() const { return m_args; }

bool ArgParser::GetFlag(const std::string& short_name,
const std::string& long_name) const {
bool ArgParser::GetFlag(const std::string& short_name, const std::string& long_name) const {
auto p_short = FindOptionByShortName(short_name);
auto p_long = FindOptionByLongName(long_name);

Expand All @@ -252,9 +234,7 @@ bool ArgParser::GetFlag(const std::string& short_name,
return p_option->parsed;
}

bool ArgParser::GetString(const std::string& short_name,
const std::string& long_name,
std::string* p_value) const {
bool ArgParser::GetString(const std::string& short_name, const std::string& long_name, std::string* p_value) const {
auto p_short = FindOptionByShortName(short_name);
auto p_long = FindOptionByLongName(long_name);

Expand All @@ -281,8 +261,7 @@ bool ArgParser::GetString(const std::string& short_name,
return true;
}

bool ArgParser::GetInt(const std::string& short_name,
const std::string& long_name, int* p_value) const {
bool ArgParser::GetInt(const std::string& short_name, const std::string& long_name, int* p_value) const {
auto p_short = FindOptionByShortName(short_name);
auto p_long = FindOptionByLongName(long_name);

Expand All @@ -309,8 +288,7 @@ bool ArgParser::GetInt(const std::string& short_name,
return true;
}

bool ArgParser::GetFloat(const std::string& short_name,
const std::string& long_name, float* p_value) const {
bool ArgParser::GetFloat(const std::string& short_name, const std::string& long_name, float* p_value) const {
auto p_short = FindOptionByShortName(short_name);
auto p_long = FindOptionByLongName(long_name);

Expand Down
78 changes: 37 additions & 41 deletions examples/arg_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,67 +3,63 @@

#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
#include <vector>

class ArgParser {
public:
enum OptionType {
OPTION_TYPE_UNDEFINED = 0,
OPTION_TYPE_FLAG,
OPTION_TYPE_STRING,
OPTION_TYPE_INT,
OPTION_TYPE_FLOAT
};
public:
enum OptionType { OPTION_TYPE_UNDEFINED = 0, OPTION_TYPE_FLAG, OPTION_TYPE_STRING, OPTION_TYPE_INT, OPTION_TYPE_FLOAT };

struct OptionValue {
std::string str;
std::string str;
union {
int i32;
float f32;
int i32;
float f32;
};
};

struct Option {
std::string short_name;
std::string long_name;
OptionType type;
std::string desc;
OptionValue value;
OptionValue default_value;
bool parsed;
std::string short_name;
std::string long_name;
OptionType type;
std::string desc;
OptionValue value;
OptionValue default_value;
bool parsed;
};

ArgParser();
~ArgParser();

bool AddFlag(const std::string& short_name, const std::string& long_name, const std::string& desc);
bool AddOptionString(const std::string& short_name, const std::string& long_name, const std::string& desc, const std::string& default_value = "");
bool AddOptionInt(const std::string& short_name, const std::string& long_name, const std::string& desc, int default_value = 0);
bool AddOptionFloat(const std::string& short_name, const std::string& long_name, const std::string& desc, float default_value = 0);
bool AddFlag(const std::string& short_name, const std::string& long_name, const std::string& desc);
bool AddOptionString(const std::string& short_name, const std::string& long_name, const std::string& desc,
const std::string& default_value = "");
bool AddOptionInt(const std::string& short_name, const std::string& long_name, const std::string& desc, int default_value = 0);
bool AddOptionFloat(const std::string& short_name, const std::string& long_name, const std::string& desc,
float default_value = 0);

bool Parse(int argc, char** argv, std::ostream& os);

bool Parse(int argc, char** argv, std::ostream& os);

size_t GetArgCount() const;
bool GetArg(size_t i, std::string* p_value) const;
size_t GetArgCount() const;
bool GetArg(size_t i, std::string* p_value) const;
const std::vector<std::string>& GetArgs() const;

bool GetFlag(const std::string& short_name, const std::string& long_name) const;
bool GetString(const std::string& short_name, const std::string& long_name, std::string* p_value) const;
bool GetInt(const std::string& short_name, const std::string& long_name, int* p_value) const;
bool GetFloat(const std::string& short_name, const std::string& long_name, float* p_value) const;
bool GetFlag(const std::string& short_name, const std::string& long_name) const;
bool GetString(const std::string& short_name, const std::string& long_name, std::string* p_value) const;
bool GetInt(const std::string& short_name, const std::string& long_name, int* p_value) const;
bool GetFloat(const std::string& short_name, const std::string& long_name, float* p_value) const;

void PrintHelp(std::ostream& os);
void PrintHelp(std::ostream& os);

private:
ArgParser::Option* FindOptionByShortName(const std::string& short_name);
const ArgParser::Option* FindOptionByShortName(const std::string& short_name) const;
ArgParser::Option* FindOptionByLongName(const std::string& long_name);
const ArgParser::Option* FindOptionByLongName(const std::string& long_name) const;
private:
ArgParser::Option* FindOptionByShortName(const std::string& short_name);
const ArgParser::Option* FindOptionByShortName(const std::string& short_name) const;
ArgParser::Option* FindOptionByLongName(const std::string& long_name);
const ArgParser::Option* FindOptionByLongName(const std::string& long_name) const;

private:
std::vector<ArgParser::Option> m_options;
std::vector<std::string> m_args;
private:
std::vector<ArgParser::Option> m_options;
std::vector<std::string> m_args;
};

#endif // __VERIFLECT_ARG_PARSER_H__
#endif // __VERIFLECT_ARG_PARSER_H__
Loading

0 comments on commit 0b0625d

Please sign in to comment.