Skip to content

Commit 061e829

Browse files
authored
Merge pull request #5597 from ab9rf/more-const-identities
add more missing `const` qualifiers
2 parents 73c103b + 7b9347d commit 061e829

File tree

5 files changed

+15
-14
lines changed

5 files changed

+15
-14
lines changed

library/DataDefs.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ const std::string df::buffer_container_identity::getFullName(const type_identity
232232
}
233233

234234
union_identity::union_identity(size_t size, const TAllocateFn alloc,
235-
compound_identity *scope_parent, const char *dfhack_name,
236-
struct_identity *parent, const struct_field_info *fields)
235+
const compound_identity *scope_parent, const char *dfhack_name,
236+
const struct_identity *parent, const struct_field_info *fields)
237237
: struct_identity(size, alloc, scope_parent, dfhack_name, parent, fields)
238238
{
239239
}
@@ -350,7 +350,7 @@ virtual_identity *virtual_identity::find(void *vtable)
350350
return NULL;
351351
}
352352

353-
void virtual_identity::adjust_vtable(virtual_ptr obj, virtual_identity *main)
353+
void virtual_identity::adjust_vtable(virtual_ptr obj, const virtual_identity *main) const
354354
{
355355
if (vtable_ptr) {
356356
*(void**)obj = vtable_ptr;

library/include/DataDefs.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,8 @@ namespace DFHack
326326
class DFHACK_EXPORT union_identity : public struct_identity {
327327
public:
328328
union_identity(size_t size, TAllocateFn alloc,
329-
compound_identity *scope_parent, const char *dfhack_name,
330-
struct_identity *parent, const struct_field_info *fields);
329+
const compound_identity *scope_parent, const char *dfhack_name,
330+
const struct_identity *parent, const struct_field_info *fields);
331331

332332
virtual identity_type type() const { return IDTYPE_UNION; }
333333

@@ -418,13 +418,13 @@ namespace DFHack
418418
template<class P> static P get_vmethod_ptr(P selector);
419419

420420
public:
421-
bool can_instantiate() { return can_allocate(); }
422-
virtual_ptr instantiate() { return can_instantiate() ? (virtual_ptr)do_allocate() : NULL; }
421+
bool can_instantiate() const { return can_allocate(); }
422+
virtual_ptr instantiate() const { return can_instantiate() ? (virtual_ptr)do_allocate() : NULL; }
423423
static virtual_ptr clone(virtual_ptr obj);
424424

425425
public:
426426
// Strictly for use in virtual class constructors
427-
void adjust_vtable(virtual_ptr obj, virtual_identity *main);
427+
void adjust_vtable(virtual_ptr obj, const virtual_identity *main) const;
428428
};
429429

430430
template<class T>
@@ -536,10 +536,10 @@ namespace df
536536
struct identity_traits {};
537537

538538
template<class T>
539-
requires requires () { { &T::_identity } -> std::convertible_to<compound_identity*>; }
539+
requires requires () { { &T::_identity } -> std::convertible_to<const compound_identity*>; }
540540
struct identity_traits<T> {
541541
static const bool is_primitive = false;
542-
static compound_identity *get() { return &T::_identity; }
542+
static const compound_identity *get() { return &T::_identity; }
543543
};
544544

545545
template<class T>

library/include/MiscUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ typename T::mapped_type findPrefixInMap(
400400
#endif
401401

402402
template<class CT>
403-
inline bool static_add_to_map(CT *pmap, typename CT::key_type key, typename CT::mapped_type value) {
403+
inline bool static_add_to_map(CT *pmap, const typename CT::key_type key, const typename CT::mapped_type value) {
404404
(*pmap)[key] = value;
405405
return true;
406406
}

library/include/modules/Gui.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ namespace DFHack
211211
/// Get the current top-level view-screen
212212
DFHACK_EXPORT df::viewscreen *getCurViewscreen(bool skip_dismissed = false);
213213

214-
DFHACK_EXPORT df::viewscreen *getViewscreenByIdentity(virtual_identity &id, int n = 1);
214+
DFHACK_EXPORT df::viewscreen *getViewscreenByIdentity(const virtual_identity &id, int n = 1);
215215

216216
/// Get the top-most underlying DF viewscreen (not owned by DFHack)
217217
DFHACK_EXPORT df::viewscreen *getDFViewscreen(bool skip_dismissed = false, df::viewscreen *top = NULL);

library/modules/Gui.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,10 @@ static std::string getNameChunk(virtual_identity *id, int start, int end)
152152
*/
153153

154154
typedef void (*getFocusStringsHandler)(std::string &str, std::vector<std::string> &strList, df::viewscreen *screen);
155-
static std::map<virtual_identity*, getFocusStringsHandler> getFocusStringsHandlers;
155+
static std::map<const virtual_identity*, getFocusStringsHandler> getFocusStringsHandlers;
156156

157157
#define VIEWSCREEN(name) df::viewscreen_##name##st
158+
158159
#define DEFINE_GET_FOCUS_STRING_HANDLER(screen_type) \
159160
static void getFocusStrings_##screen_type(const std::string &baseFocus, std::vector<std::string> &focusStrings, VIEWSCREEN(screen_type) *screen);\
160161
DFHACK_STATIC_ADD_TO_MAP(\
@@ -2718,7 +2719,7 @@ df::viewscreen *Gui::getCurViewscreen(bool skip_dismissed)
27182719
return ws;
27192720
}
27202721

2721-
df::viewscreen *Gui::getViewscreenByIdentity (virtual_identity &id, int n)
2722+
df::viewscreen *Gui::getViewscreenByIdentity (const virtual_identity &id, int n)
27222723
{
27232724
bool limit = (n > 0);
27242725
df::viewscreen *screen = Gui::getCurViewscreen();

0 commit comments

Comments
 (0)