Functions returning a string reference must not be cast to functions returning a string object

feature/pre-code-move
kaetemi 5 years ago committed by Jan Boon
parent 695ebeb0ef
commit 02270e7113

@ -215,7 +215,7 @@ namespace NLGUI
// Browser home
std::string Home;
// Get Home URL
virtual std::string home();
virtual std::string home() const;
// Undo browse: Browse the precedent url browsed. no op if none
void browseUndo ();

@ -181,7 +181,7 @@ namespace NLGUI
REFLECT_STRING("AHParamsClose", getAHParamsClose, setAHParamsClose);
REFLECT_BOOL("Opened", getOpened, setOpened);
REFLECT_BOOL("Show", getShow, setShow);
REFLECT_UCSTRING("Text", getText, setText);
REFLECT_UCSTRING_REF("Text", getText, setText);
// lua
REFLECT_LUA_METHOD("getNumChildren", luaGetNumChildren);
REFLECT_LUA_METHOD("getChild", luaGetChild);

@ -365,10 +365,6 @@ namespace NLGUI
void setModulateGlobalColor(bool state) {_ModulateGlobalColor= state;}
bool getModulateGlobalColor() const {return _ModulateGlobalColor;}
void dummySet(sint32 value);
void dummySet(const std::string &value);
// lua methods
int luaUpdateCoords(CLuaState &ls);
int luaInvalidateCoords(CLuaState &ls);
@ -382,6 +378,11 @@ namespace NLGUI
std::string getSizeRefAsString() const;
std::string getSizeRefAsString( const sint32 &sizeRef, const sint32 &sizeDivW, const sint32 &sizeDivH ) const;
void dummySet(sint32 value);
void dummySet(const std::string &value);
public:
// export some properties
REFLECT_EXPORT_START(CInterfaceElement, CReflectable)
REFLECT_BOOL ("active", getActive, setActive);

@ -234,18 +234,18 @@ namespace NLGUI
REFLECT_LUA_METHOD("dumpSize", luaDumpSize);
REFLECT_LUA_METHOD("dumpEltsOrder", luaDumpEltsOrder);
REFLECT_LUA_METHOD("dumpGroups", luaDumpGroups);
REFLECT_STRING ("left_click", getLeftClickHandler, setLeftClickHandler);
REFLECT_STRING ("right_click", getRightClickHandler, setRightClickHandler);
REFLECT_STRING ("left_click_params", getLeftClickHandlerParams, setLeftClickHandlerParams);
REFLECT_STRING ("right_click_params", getRightClickHandlerParams, setRightClickHandlerParams);
REFLECT_STRING ("on_active", getOnActiveHandler, setOnActiveHandler);
REFLECT_STRING ("on_active_params", getOnActiveParams, setOnActiveParams);
REFLECT_STRING ("on_deactive", getOnDeactiveHandler, setOnDeactiveHandler);
REFLECT_STRING ("on_deactive_params", getOnDeactiveParams, setOnDeactiveParams);
REFLECT_STRING ("on_enter", getAHOnEnter, setAHOnEnter);
REFLECT_STRING ("on_enter_params", getAHOnEnterParams, setAHOnEnterParams);
REFLECT_STRING ("on_escape", getAHOnEscape, setAHOnEscape);
REFLECT_STRING ("on_escape_params", getAHOnEscapeParams, setAHOnEscapeParams);
REFLECT_STRING_REF ("left_click", getLeftClickHandler, setLeftClickHandler);
REFLECT_STRING_REF ("right_click", getRightClickHandler, setRightClickHandler);
REFLECT_STRING_REF ("left_click_params", getLeftClickHandlerParams, setLeftClickHandlerParams);
REFLECT_STRING_REF ("right_click_params", getRightClickHandlerParams, setRightClickHandlerParams);
REFLECT_STRING_REF ("on_active", getOnActiveHandler, setOnActiveHandler);
REFLECT_STRING_REF ("on_active_params", getOnActiveParams, setOnActiveParams);
REFLECT_STRING_REF ("on_deactive", getOnDeactiveHandler, setOnDeactiveHandler);
REFLECT_STRING_REF ("on_deactive_params", getOnDeactiveParams, setOnDeactiveParams);
REFLECT_STRING_REF ("on_enter", getAHOnEnter, setAHOnEnter);
REFLECT_STRING_REF ("on_enter_params", getAHOnEnterParams, setAHOnEnterParams);
REFLECT_STRING_REF ("on_escape", getAHOnEscape, setAHOnEscape);
REFLECT_STRING_REF ("on_escape_params", getAHOnEscapeParams, setAHOnEscapeParams);
REFLECT_SINT32 ("ofsx", getOfsX, setOfsX);
REFLECT_SINT32 ("ofsy", getOfsY, setOfsY);
REFLECT_BOOL("child_resize_w", getResizeFromChildW, setResizeFromChildW);

@ -42,6 +42,8 @@ namespace NLGUI
Float,
String,
UCString,
StringRef,
UCStringRef,
RGBA,
LuaMethod
}; // other types will be added when needed
@ -52,6 +54,8 @@ namespace NLGUI
typedef float (CReflectable::* TGetFloat) () const;
typedef std::string (CReflectable::* TGetString) () const;
typedef ucstring (CReflectable::* TGetUCString) () const;
typedef const std::string & (CReflectable::* TGetStringRef) () const;
typedef const ucstring & (CReflectable::* TGetUCStringRef) () const;
typedef NLMISC::CRGBA (CReflectable::* TGetRGBA) () const;
//
typedef void (CReflectable::* TSetBool) (bool);
@ -75,6 +79,8 @@ namespace NLGUI
TGetFloat GetFloat;
TGetString GetString;
TGetUCString GetUCString;
TGetStringRef GetStringRef;
TGetUCStringRef GetUCStringRef;
TGetRGBA GetRGBA;
TLuaMethod GetLuaMethod; // lua method can only be obtained, not written ...
} GetMethod;
@ -108,7 +114,7 @@ namespace NLGUI
public:
virtual ~CReflectable() {}
virtual const char *getReflectedClassName() const { return "CReflectable"; }
virtual const char *getRflectedParentClassName() const { return ""; }
virtual const char *getReflectedParentClassName() const { return ""; }
/** When registering classes, the reflect system will call this function on each class
* to know which properties they exports.
@ -211,8 +217,8 @@ namespace NLGUI
* Should be placed inside the class
*/
#define REFLECT_EXPORT_START(className, parentName) \
virtual const char *getReflectedClassName() const { return #className; } \
virtual const char *getReflectedParentClassName() const { return #parentName; } \
virtual const char *getReflectedClassName() const NL_OVERRIDE { return #className; } \
virtual const char *getReflectedParentClassName() const NL_OVERRIDE { return #parentName; } \
static void getReflectedProperties(TReflectedProperties &props) \
{ \
typedef className A; \
@ -222,6 +228,8 @@ namespace NLGUI
typedef float (className::* TGetFloata) () const; \
typedef std::string (className::* TGetStringa) () const; \
typedef ucstring (className::* TGetUCStringa) () const; \
typedef const std::string & (className::* TGetStringRefa) () const; \
typedef const ucstring & (className::* TGetUCStringRefa) () const; \
typedef NLMISC::CRGBA (className::* TGetRGBAa) () const; \
typedef void (className::* TSetBoola) (bool); \
typedef void (className::* TSetSInt32a) (sint32); \
@ -240,8 +248,8 @@ namespace NLGUI
CReflectedProperty prop; \
prop.Name = exportName; \
prop.Type = CReflectedProperty::Boolean; \
prop.GetMethod.GetBool = (CReflectedProperty::TGetBool) (TGetBoola) &A::getMethod; \
prop.SetMethod.SetBool = (CReflectedProperty::TSetBool) (TSetBoola) &A::setMethod; \
prop.GetMethod.GetBool = (CReflectedProperty::TGetBool) static_cast<TGetBoola>(&A::getMethod); \
prop.SetMethod.SetBool = (CReflectedProperty::TSetBool) static_cast<TSetBoola>(&A::setMethod); \
props.push_back(prop); \
}
@ -251,8 +259,8 @@ namespace NLGUI
CReflectedProperty prop; \
prop.Name = exportName; \
prop.Type = CReflectedProperty::SInt32; \
prop.GetMethod.GetSInt32 = (CReflectedProperty::TGetSInt32) (TGetSInt32a) &A::getMethod; \
prop.SetMethod.SetSInt32 = (CReflectedProperty::TSetSInt32) (TSetSInt32a) &A::setMethod; \
prop.GetMethod.GetSInt32 = (CReflectedProperty::TGetSInt32) static_cast<TGetSInt32a>(&A::getMethod); \
prop.SetMethod.SetSInt32 = (CReflectedProperty::TSetSInt32) static_cast<TSetSInt32a>(&A::setMethod); \
props.push_back(prop); \
}
@ -262,8 +270,8 @@ namespace NLGUI
CReflectedProperty prop; \
prop.Name = exportName; \
prop.Type = CReflectedProperty::UInt32; \
prop.GetMethod.GetUInt32 = (CReflectedProperty::TGetUInt32) (TGetUInt32a) &A::getMethod; \
prop.SetMethod.SetUInt32 = (CReflectedProperty::TSetUInt32) (TSetUInt32a) &A::setMethod; \
prop.GetMethod.GetUInt32 = (CReflectedProperty::TGetUInt32) static_cast<TGetUInt32a>(&A::getMethod); \
prop.SetMethod.SetUInt32 = (CReflectedProperty::TSetUInt32) static_cast<TSetUInt32a>(&A::setMethod); \
props.push_back(prop); \
}
@ -273,8 +281,8 @@ namespace NLGUI
CReflectedProperty prop; \
prop.Name = exportName; \
prop.Type = CReflectedProperty::Float; \
prop.GetMethod.GetFloat = (CReflectedProperty::TGetFloat) (TGetFloata) &A::getMethod; \
prop.SetMethod.SetFloat = (CReflectedProperty::TSetFloat) (TSetFloata) &A::setMethod; \
prop.GetMethod.GetFloat = (CReflectedProperty::TGetFloat) static_cast<TGetFloata>(&A::getMethod); \
prop.SetMethod.SetFloat = (CReflectedProperty::TSetFloat) static_cast<TSetFloata>(&A::setMethod); \
props.push_back(prop); \
}
@ -284,8 +292,8 @@ namespace NLGUI
CReflectedProperty prop; \
prop.Name = exportName; \
prop.Type = CReflectedProperty::String; \
prop.GetMethod.GetString = (CReflectedProperty::TGetString) (TGetStringa) &A::getMethod; \
prop.SetMethod.SetString = (CReflectedProperty::TSetString) (TSetStringa) &A::setMethod; \
prop.GetMethod.GetString = (CReflectedProperty::TGetString) static_cast<TGetStringa>(&A::getMethod); \
prop.SetMethod.SetString = (CReflectedProperty::TSetString) static_cast<TSetStringa>(&A::setMethod); \
props.push_back(prop); \
}
@ -295,8 +303,30 @@ namespace NLGUI
CReflectedProperty prop; \
prop.Name = exportName; \
prop.Type = CReflectedProperty::UCString; \
prop.GetMethod.GetUCString = (CReflectedProperty::TGetUCString) (TGetUCStringa) &A::getMethod; \
prop.SetMethod.SetUCString = (CReflectedProperty::TSetUCString) (TSetUCStringa) &A::setMethod; \
prop.GetMethod.GetUCString = (CReflectedProperty::TGetUCString) static_cast<TGetUCStringa>(&A::getMethod); \
prop.SetMethod.SetUCString = (CReflectedProperty::TSetUCString) static_cast<TSetUCStringa>(&A::setMethod); \
props.push_back(prop); \
}
// export a string value, by giving the name of the get and the set method
#define REFLECT_STRING_REF(exportName, getMethod, setMethod) \
{ \
CReflectedProperty prop; \
prop.Name = exportName; \
prop.Type = CReflectedProperty::StringRef; \
prop.GetMethod.GetStringRef = (CReflectedProperty::TGetStringRef) static_cast<TGetStringRefa>(&A::getMethod); \
prop.SetMethod.SetString = (CReflectedProperty::TSetString) static_cast<TSetStringa>(&A::setMethod); \
props.push_back(prop); \
}
// export a unicode string value, by giving the name of the get and the set method
#define REFLECT_UCSTRING_REF(exportName, getMethod, setMethod) \
{ \
CReflectedProperty prop; \
prop.Name = exportName; \
prop.Type = CReflectedProperty::UCStringRef; \
prop.GetMethod.GetUCStringRef = (CReflectedProperty::TGetUCStringRef) static_cast<TGetUCStringRefa>(&A::getMethod); \
prop.SetMethod.SetUCString = (CReflectedProperty::TSetUCString) static_cast<TSetUCStringa>(&A::setMethod); \
props.push_back(prop); \
}
@ -307,8 +337,8 @@ namespace NLGUI
CReflectedProperty prop; \
prop.Name = exportName; \
prop.Type = CReflectedProperty::RGBA; \
prop.GetMethod.GetRGBA = (CReflectedProperty::TGetRGBA) (TGetRGBAa) &A::getMethod; \
prop.SetMethod.SetRGBA = (CReflectedProperty::TSetRGBA) (TSetRGBAa) &A::setMethod; \
prop.GetMethod.GetRGBA = (CReflectedProperty::TGetRGBA) static_cast<TGetRGBAa>(&A::getMethod); \
prop.SetMethod.SetRGBA = (CReflectedProperty::TSetRGBA) static_cast<TSetRGBAa>(&A::setMethod); \
props.push_back(prop); \
}
@ -318,7 +348,7 @@ namespace NLGUI
CReflectedProperty prop; \
prop.Name = exportName; \
prop.Type = CReflectedProperty::LuaMethod; \
prop.GetMethod.GetLuaMethod = (CReflectedProperty::TLuaMethod) (TLuaMethoda) &A::method; \
prop.GetMethod.GetLuaMethod = (CReflectedProperty::TLuaMethod) static_cast<TLuaMethoda>(&A::method); \
props.push_back(prop); \
}

@ -589,7 +589,7 @@ template<class T, class U> inline T type_cast(U o)
/** Compile time assertion
*/
#ifdef NL_ISO_CPP0X_AVAILABLE
# define nlctassert(cond) static_assert(cond, "Compile time assert in "#cond)
# define nlctassert(cond) static_assert((cond), "Compile time assert in "#cond)
#else
# define nlctassert(cond) (void)sizeof(uint[(cond) ? 1 : 0])
#endif

@ -4318,7 +4318,7 @@ namespace NLGUI
// ***************************************************************************
string CGroupHTML::home ()
string CGroupHTML::home () const
{
return Home;
}

@ -555,6 +555,12 @@ namespace NLGUI
case CReflectedProperty::UCString:
result.setUCString ((elem->*(pRP->GetMethod.GetUCString))());
break;
case CReflectedProperty::StringRef:
result.setString ((elem->*(pRP->GetMethod.GetStringRef))());
break;
case CReflectedProperty::UCStringRef:
result.setUCString ((elem->*(pRP->GetMethod.GetUCStringRef))());
break;
case CReflectedProperty::RGBA:
result.setRGBA ((elem->*(pRP->GetMethod.GetRGBA))());
break;

@ -106,6 +106,7 @@ namespace NLGUI
}
break;
case CReflectedProperty::String:
case CReflectedProperty::StringRef:
if (valueToAffect.toString())
{
(destElem.*(property.SetMethod.SetString))(valueToAffect.getString());
@ -117,6 +118,7 @@ namespace NLGUI
}
break;
case CReflectedProperty::UCString:
case CReflectedProperty::UCStringRef:
if (valueToAffect.toString())
{
(destElem.*(property.SetMethod.SetUCString))(valueToAffect.getUCString());

@ -1435,6 +1435,20 @@ namespace NLGUI
#endif
}
break;
case CReflectedProperty::UCStringRef:
{
ucstring str = (reflectedObject.*(property.GetMethod.GetUCStringRef))();
#if LUABIND_VERSION > 600
luabind::detail::push(ls.getStatePointer(), str);
#else
luabind::object obj(ls.getStatePointer(), str);
obj.pushvalue();
#endif
}
break;
case CReflectedProperty::StringRef:
ls.push( (reflectedObject.*(property.GetMethod.GetStringRef))() );
break;
case CReflectedProperty::RGBA:
{
CRGBA color = (reflectedObject.*(property.GetMethod.GetRGBA))();
@ -1499,6 +1513,7 @@ namespace NLGUI
return;
}
case CReflectedProperty::String:
case CReflectedProperty::StringRef:
{
std::string val;
ls.toString(stackIndex, val);
@ -1506,6 +1521,7 @@ namespace NLGUI
return;
}
case CReflectedProperty::UCString:
case CReflectedProperty::UCStringRef:
{
ucstring val;
// Additionaly return of CInterfaceExpr may be std::string... test std string too

@ -296,14 +296,14 @@ public:
REFLECT_SINT32("symbol", getGuildSymbol, setGuildSymbol);
REFLECT_BOOL("invert_symbol", getInvertGuildSymbol, setInvertGuildSymbol);
REFLECT_BOOL("can_drop", getCanDrop, setCanDrop);
REFLECT_STRING ("left_click", getActionOnLeftClick, setActionOnLeftClick);
REFLECT_STRING ("right_click", getActionOnRightClick, setActionOnRightClick);
REFLECT_STRING ("left_click_params", getParamsOnLeftClick, setParamsOnLeftClick);
REFLECT_STRING ("right_click_params", getParamsOnRightClick, setParamsOnRightClick);
REFLECT_STRING ("on_drop", getActionOnDrop, setActionOnDrop);
REFLECT_STRING ("on_drop_params", getParamsOnDrop, setParamsOnDrop);
REFLECT_STRING ("on_can_drop", getActionOnCanDrop, setActionOnCanDrop);
REFLECT_STRING ("on_can_drop_params", getParamsOnCanDrop, setParamsOnCanDrop);
REFLECT_STRING_REF ("left_click", getActionOnLeftClick, setActionOnLeftClick);
REFLECT_STRING_REF ("right_click", getActionOnRightClick, setActionOnRightClick);
REFLECT_STRING_REF ("left_click_params", getParamsOnLeftClick, setParamsOnLeftClick);
REFLECT_STRING_REF ("right_click_params", getParamsOnRightClick, setParamsOnRightClick);
REFLECT_STRING_REF ("on_drop", getActionOnDrop, setActionOnDrop);
REFLECT_STRING_REF ("on_drop_params", getParamsOnDrop, setParamsOnDrop);
REFLECT_STRING_REF ("on_can_drop", getActionOnCanDrop, setActionOnCanDrop);
REFLECT_STRING_REF ("on_can_drop_params", getParamsOnCanDrop, setParamsOnCanDrop);
REFLECT_LUA_METHOD("getDraggedSheet", luaGetDraggedSheet);
REFLECT_LUA_METHOD("getItemInfo", luaGetItemInfo);
REFLECT_LUA_METHOD("getName", luaGetName);

@ -88,7 +88,7 @@ void CGroupHTMLCS::addHTTPPostParams (SFormFields &formfields, bool /*trustedDom
// ***************************************************************************
string CGroupHTMLCS::home ()
string CGroupHTMLCS::home () const
{
return Home;
}

@ -45,7 +45,7 @@ public:
// From CGroupHTML
virtual void addHTTPGetParams (std::string &url, bool trustedDomain);
virtual void addHTTPPostParams (SFormFields &formfields, bool trustedDomain);
virtual std::string home();
virtual std::string home() const NL_OVERRIDE;
private:

@ -108,10 +108,10 @@ void CGroupHTMLForum::addHTTPPostParams (SFormFields &formfields, bool /*trusted
// ***************************************************************************
string CGroupHTMLForum::home ()
string CGroupHTMLForum::home () const
{
CInterfaceManager *pIM = CInterfaceManager::getInstance();
NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:FORUM_UPDATED")->setValue32(0);
NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:FORUM_UPDATED")->setValue32(0); // FIXME: How is this const?!
return Home;
}

@ -45,7 +45,7 @@ public:
// From CGroupHTML
virtual void addHTTPGetParams (std::string &url, bool trustedDomain);
virtual void addHTTPPostParams (SFormFields &formfields, bool trustedDomain);
virtual std::string home();
virtual std::string home() const NL_OVERRIDE;
virtual void handle ();
private:

@ -77,10 +77,10 @@ void CGroupHTMLMail::addHTTPPostParams (SFormFields &formfields, bool /*trustedD
// ***************************************************************************
string CGroupHTMLMail::home ()
string CGroupHTMLMail::home () const
{
CInterfaceManager *pIM = CInterfaceManager::getInstance();
NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:MAIL_WAITING")->setValue32(0);
NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:MAIL_WAITING")->setValue32(0); // FIXME: How is this const?!
return Home;
}

@ -45,7 +45,7 @@ public:
// From CGroupHTML
virtual void addHTTPGetParams (std::string &url, bool trustedDomain);
virtual void addHTTPPostParams (SFormFields &formfields, bool trustedDomain);
virtual std::string home();
virtual std::string home() const NL_OVERRIDE;
virtual void handle ();
private:

@ -396,7 +396,7 @@ void CGroupHTMLAuth::addHTTPPostParams (SFormFields &formfields, bool trustedDom
// ***************************************************************************
string CGroupHTMLAuth::home ()
string CGroupHTMLAuth::home () const
{
return Home;
}
@ -442,7 +442,7 @@ void CGroupHTMLWebIG::addHTTPPostParams (SFormFields &formfields, bool trustedDo
// ***************************************************************************
string CGroupHTMLWebIG::home ()
string CGroupHTMLWebIG::home () const
{
return Home;
}

@ -41,7 +41,7 @@ public:
// From CGroupHTML
virtual void addHTTPGetParams (std::string &url, bool trustedDomain);
virtual void addHTTPPostParams (SFormFields &formfields, bool trustedDomain);
virtual std::string home();
virtual std::string home() const NL_OVERRIDE;
virtual void handle ();
private:
@ -63,7 +63,7 @@ public:
/// From CGroupHTMLAuth
virtual void addHTTPGetParams (std::string &url, bool trustedDomain);
virtual void addHTTPPostParams (SFormFields &formfields, bool trustedDomain);
virtual std::string home();
virtual std::string home() const NL_OVERRIDE;
virtual void handle ();
private:

@ -348,7 +348,7 @@ void CGroupQuickHelp::browse (const char *url)
// ***************************************************************************
std::string CGroupQuickHelp::home()
std::string CGroupQuickHelp::home() const
{
string completeURL = getLanguageUrl(Home, ClientCfg.getHtmlLanguageCode());

@ -53,7 +53,7 @@ private:
virtual void beginElement (NLGUI::CHtmlElement &elm);
virtual void endBuild ();
virtual void browse (const char *url);
virtual std::string home();
virtual std::string home() const NL_OVERRIDE;
// Modify uri with '.html' or '_??.html' ending to have current user language,
// If the uri is not found locally, then try "en" as fallback language

Loading…
Cancel
Save