fix: function returns by const value
This commit is contained in:
parent
d292ef130c
commit
a5dc187481
@ -42,10 +42,10 @@ const std::string& GLSLExtension::getHeader(const std::string& name) const {
|
||||
return found->second;
|
||||
}
|
||||
|
||||
const std::string GLSLExtension::getDefine(const std::string& name) const {
|
||||
const std::string& GLSLExtension::getDefine(const std::string& name) const {
|
||||
auto found = defines.find(name);
|
||||
if (found == defines.end()) {
|
||||
return "";
|
||||
throw std::runtime_error("name '"+name+"' is not defined");
|
||||
}
|
||||
return found->second;
|
||||
}
|
||||
@ -84,7 +84,7 @@ inline void source_line(std::stringstream& ss, uint linenum) {
|
||||
ss << "#line " << linenum << "\n";
|
||||
}
|
||||
|
||||
const std::string GLSLExtension::process(const fs::path& file, const std::string& source) {
|
||||
std::string GLSLExtension::process(const fs::path& file, const std::string& source) {
|
||||
std::stringstream ss;
|
||||
size_t pos = 0;
|
||||
uint linenum = 1;
|
||||
|
||||
@ -24,12 +24,12 @@ public:
|
||||
void addHeader(const std::string& name, std::string source);
|
||||
|
||||
const std::string& getHeader(const std::string& name) const;
|
||||
const std::string getDefine(const std::string& name) const;
|
||||
const std::string& getDefine(const std::string& name) const;
|
||||
|
||||
bool hasHeader(const std::string& name) const;
|
||||
bool hasDefine(const std::string& name) const;
|
||||
|
||||
const std::string process(
|
||||
std::string process(
|
||||
const std::filesystem::path& file,
|
||||
const std::string& source
|
||||
);
|
||||
|
||||
@ -120,7 +120,7 @@ const std::string& Node::getTag() const {
|
||||
return tag;
|
||||
}
|
||||
|
||||
const xmlattribute Node::attr(const std::string& name) const {
|
||||
const xmlattribute& Node::attr(const std::string& name) const {
|
||||
auto found = attrs.find(name);
|
||||
if (found == attrs.end()) {
|
||||
throw std::runtime_error("element <"+tag+" ...> missing attribute "+name);
|
||||
@ -128,7 +128,7 @@ const xmlattribute Node::attr(const std::string& name) const {
|
||||
return found->second;
|
||||
}
|
||||
|
||||
const xmlattribute Node::attr(const std::string& name, const std::string& def) const {
|
||||
xmlattribute Node::attr(const std::string& name, const std::string& def) const {
|
||||
auto found = attrs.find(name);
|
||||
if (found == attrs.end()) {
|
||||
return Attribute(name, def);
|
||||
|
||||
@ -68,14 +68,14 @@ namespace xml {
|
||||
/// @param name attribute name
|
||||
/// @throws std::runtime_error if element has no attribute
|
||||
/// @return xmlattribute - {name, value}
|
||||
const xmlattribute attr(const std::string& name) const;
|
||||
const xmlattribute& attr(const std::string& name) const;
|
||||
|
||||
/// @brief Get attribute by name
|
||||
/// @param name attribute name
|
||||
/// @param def default value will be returned wrapped in xmlattribute
|
||||
/// if element has no attribute
|
||||
/// @return xmlattribute - {name, value} or {name, def} if not found*/
|
||||
const xmlattribute attr(const std::string& name, const std::string& def) const;
|
||||
xmlattribute attr(const std::string& name, const std::string& def) const;
|
||||
|
||||
/// @brief Check if element has attribute
|
||||
/// @param name attribute name
|
||||
|
||||
@ -33,11 +33,11 @@ const std::string& UiDocument::getId() const {
|
||||
return id;
|
||||
}
|
||||
|
||||
const std::shared_ptr<gui::UINode> UiDocument::getRoot() const {
|
||||
std::shared_ptr<gui::UINode> UiDocument::getRoot() const {
|
||||
return root;
|
||||
}
|
||||
|
||||
const std::shared_ptr<gui::UINode> UiDocument::get(const std::string& id) const {
|
||||
std::shared_ptr<gui::UINode> UiDocument::get(const std::string& id) const {
|
||||
auto found = map.find(id);
|
||||
if (found == map.end()) {
|
||||
return nullptr;
|
||||
|
||||
@ -41,8 +41,8 @@ public:
|
||||
const std::string& getId() const;
|
||||
const uinodes_map& getMap() const;
|
||||
uinodes_map& getMapWriteable();
|
||||
const std::shared_ptr<gui::UINode> getRoot() const;
|
||||
const std::shared_ptr<gui::UINode> get(const std::string& id) const;
|
||||
std::shared_ptr<gui::UINode> getRoot() const;
|
||||
std::shared_ptr<gui::UINode> get(const std::string& id) const;
|
||||
const uidocscript& getScript() const;
|
||||
scriptenv getEnvironment() const;
|
||||
|
||||
|
||||
@ -114,8 +114,21 @@ SlotView::SlotView(
|
||||
}
|
||||
|
||||
void SlotView::draw(const DrawContext* pctx, Assets* assets) {
|
||||
if (bound == nullptr)
|
||||
if (bound == nullptr) {
|
||||
return;
|
||||
}
|
||||
itemid_t itemid = bound->getItemId();
|
||||
if (itemid != prevItem) {
|
||||
if (itemid) {
|
||||
auto def = content->getIndices()->getItemDef(itemid);
|
||||
tooltip = util::pascal_case(
|
||||
langs::get(util::str2wstr_utf8(def->caption))
|
||||
);
|
||||
} else {
|
||||
tooltip = L"";
|
||||
}
|
||||
}
|
||||
prevItem = itemid;
|
||||
|
||||
const int slotSize = InventoryView::SLOT_SIZE;
|
||||
|
||||
@ -274,15 +287,12 @@ void SlotView::onFocus(gui::GUI* gui) {
|
||||
clicked(gui, mousecode::BUTTON_1);
|
||||
}
|
||||
|
||||
const std::wstring SlotView::getTooltip() const {
|
||||
const auto str = UINode::getTooltip();
|
||||
if (!str.empty() || bound->isEmpty()) {
|
||||
const std::wstring& SlotView::getTooltip() const {
|
||||
const auto& str = UINode::getTooltip();
|
||||
if (!str.empty() || tooltip.empty()) {
|
||||
return str;
|
||||
}
|
||||
auto def = content->getIndices()->getItemDef(bound->getItemId());
|
||||
return util::pascal_case(
|
||||
langs::get(util::str2wstr_utf8(def->caption))
|
||||
); // TODO: cache
|
||||
return tooltip;
|
||||
}
|
||||
|
||||
void SlotView::bind(
|
||||
|
||||
@ -53,6 +53,9 @@ namespace gui {
|
||||
|
||||
int64_t inventoryid = 0;
|
||||
ItemStack* bound = nullptr;
|
||||
|
||||
std::wstring tooltip;
|
||||
itemid_t prevItem = 0;
|
||||
public:
|
||||
SlotView(SlotLayout layout);
|
||||
|
||||
@ -63,7 +66,7 @@ namespace gui {
|
||||
|
||||
virtual void clicked(gui::GUI*, mousecode) override;
|
||||
virtual void onFocus(gui::GUI*) override;
|
||||
virtual const std::wstring getTooltip() const override;
|
||||
virtual const std::wstring& getTooltip() const override;
|
||||
|
||||
void bind(
|
||||
int64_t inventoryid,
|
||||
|
||||
@ -138,7 +138,7 @@ void UINode::setTooltip(const std::wstring& text) {
|
||||
this->tooltip = text;
|
||||
}
|
||||
|
||||
const std::wstring UINode::getTooltip() const {
|
||||
const std::wstring& UINode::getTooltip() const {
|
||||
return tooltip;
|
||||
}
|
||||
|
||||
|
||||
@ -202,7 +202,7 @@ namespace gui {
|
||||
virtual bool isResizing() const;
|
||||
|
||||
virtual void setTooltip(const std::wstring& text);
|
||||
virtual const std::wstring getTooltip() const;
|
||||
virtual const std::wstring& getTooltip() const;
|
||||
|
||||
virtual void setTooltipDelay(float delay);
|
||||
virtual float getTooltipDelay() const;
|
||||
|
||||
@ -120,7 +120,7 @@ namespace cmd {
|
||||
);
|
||||
Command* get(const std::string& name);
|
||||
|
||||
const std::unordered_map<std::string, Command> getCommands() const {
|
||||
const std::unordered_map<std::string, Command>& getCommands() const {
|
||||
return commands;
|
||||
}
|
||||
};
|
||||
|
||||
@ -68,7 +68,7 @@ LuaState::LuaState() {
|
||||
setglobal(LAMBDAS_TABLE);
|
||||
}
|
||||
|
||||
const std::string LuaState::envName(int env) {
|
||||
std::string LuaState::envName(int env) {
|
||||
return "_ENV"+util::mangleid(env);
|
||||
}
|
||||
|
||||
|
||||
@ -29,7 +29,7 @@ namespace lua {
|
||||
LuaState();
|
||||
~LuaState();
|
||||
|
||||
static const std::string envName(int env);
|
||||
static std::string envName(int env);
|
||||
void loadbuffer(int env, const std::string& src, const std::string& file);
|
||||
int gettop() const;
|
||||
int pushivec3(lua_Integer x, lua_Integer y, lua_Integer z);
|
||||
|
||||
@ -157,7 +157,7 @@ struct Binding {
|
||||
void reset(keycode);
|
||||
void reset(mousecode);
|
||||
|
||||
inline const std::string text() const {
|
||||
inline std::string text() const {
|
||||
switch (type) {
|
||||
case inputtype::keyboard: {
|
||||
return input_util::to_string(static_cast<keycode>(code));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user