Merge branch 'develop' into ryzomclassic-develop

ryzomclassic-develop
Jan Boon 5 years ago
commit 1f7fca7df3

@ -106,10 +106,8 @@ public:
class ITexture : public CBitmap, public NLMISC::CRefCount, public NLMISC::IStreamable
{
public:
#ifndef RYZOM_FORGE
NL_USES_DEFAULT_ARENA_OBJECT_ALLOCATOR // for fast alloc
#endif
// TODO: FIX: NL_USES_DEFAULT_ARENA_OBJECT_ALLOCATOR // for fast alloc
// Those enums MUST be the same than in UTexture!!
enum TWrapMode
{

@ -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

@ -1243,13 +1243,15 @@ CObject* CComLuaModule::getObjectFromLua(lua_State* state, sint idx)
#if LUA_VERSION_NUM >= 503
if (lua_isinteger(state, -1) != 0)
{
nlctassert(sizeof(lua_Integer) == sizeof(sint64));
sint64 value = lua_tointeger(state, -1);
lua_pop(state, 1);
return new CObjectInteger(value);
return new CObjectNumber(value);
}
else
#endif
{
nlctassert(sizeof(lua_Number) == sizeof(double));
double value = lua_tonumber(state, -1);
lua_pop(state, 1);
return new CObjectNumber(value);
@ -1259,7 +1261,7 @@ CObject* CComLuaModule::getObjectFromLua(lua_State* state, sint idx)
case LUA_TBOOLEAN:
{
double value = static_cast<double>(lua_toboolean(state, -1));
sint64 value = lua_toboolean(state, -1);
lua_pop(state, 1);
return new CObjectNumber(value);
}

@ -66,19 +66,17 @@ class CCallbackClientAdaptor : public CNelCallbackClientAdaptor
virtual void send(const NLNET::CMessage &buffer, NLNET::TSockId hostid = NLNET::InvalidSockId, bool log = true)
{
CAutoMutex<CUnfairMutex> mutex1(_Mutex);
CAutoMutex<CUnfairMutex> mutex(_Mutex);
if (!_PassThrue)
{
// queue the message for later sending.
nldebug("SB: Pushing a buffer into SendQueue (from %u elts)", _SendQueue.size());
CAutoMutex<CUnfairMutex> mutex(_Mutex);
_SendQueue.push(buffer);
}
else
{
// protect socket because update() can be called in the main thread while send() can be called with passthru=true in the session browser thread (by authenticate() for example)
CAutoMutex<CUnfairMutex> mutex(_Mutex);
_CallbackClient.send(buffer, hostid, log);
}
}

@ -175,12 +175,6 @@ void CObject::inPlaceCopy(const CObjectNumber &src)
copyMismatchMsg(src);
}
void CObject::inPlaceCopy(const CObjectInteger &src)
{
//H_AUTO(R2_CObject_inPlaceCopy)
copyMismatchMsg(src);
}
void CObject::inPlaceCopy(const CObjectTable &src)
{
//H_AUTO(R2_CObject_inPlaceCopy)
@ -764,7 +758,15 @@ void CObjectRefId::doSerialize(std::string& out, CSerializeContext& /* context
//----------------------- CObjectNumber ----------------------------------------
CObjectNumber::CObjectNumber(double value) : CObject(), _Value(value){}
CObjectNumber::CObjectNumber(double value) : CObject(), m_IsInteger(false)
{
m_Value.Number = value;
}
CObjectNumber::CObjectNumber(sint64 value) : CObject(), m_IsInteger(true)
{
m_Value.Integer = value;
}
const char *CObjectNumber::getTypeAsString() const
{
@ -787,185 +789,141 @@ void CObjectNumber::inPlaceCopyTo(CObject &dest) const
void CObjectNumber::inPlaceCopy(const CObjectNumber &src)
{
//H_AUTO(R2_CObjectNumber_inPlaceCopy)
_Value = src._Value;
m_IsInteger = src.m_IsInteger;
m_Value.Integer = src.m_Value.Integer;
setGhost(src.getGhost());
}
std::string CObjectNumber::doToString() const { return NLMISC::toString("%lf", _Value);}
std::string CObjectNumber::doToString() const { return m_IsInteger ? NLMISC::toString(m_Value.Integer) : NLMISC::toString("%lf", m_Value.Number);}
void CObjectNumber::doSerialize(std::string& out, CSerializeContext& /* context */) const
{
//H_AUTO(R2_CObjectNumber_doSerialize)
nlassert(!getGhost());
//out.precision(15);
std::string value = NLMISC::toString(double(sint64(_Value * 1000.0 + (_Value>=0.0?0.5:-0.5)))/1000.0);
// search for first not 0 value from the end
std::string::size_type pos = value.find_last_not_of('0');
if (pos != std::string::npos)
if (doIsInteger())
{
out += NLMISC::toString(getIntegerValue());
}
else
{
// don't remove character at pos if it's another digit
if (value[pos] != '.') ++pos;
value.erase(pos);
//out.precision(15);
double num = getNumberValue();
// TODO: WTF is this for?!
std::string value = NLMISC::toString(double(sint64(num * 1000.0 + (num>=0.0?0.5:-0.5)))/1000.0);
// search for first not 0 value from the end
std::string::size_type pos = value.find_last_not_of('0');
if (pos != std::string::npos)
{
// don't remove character at pos if it's another digit
if (value[pos] != '.') ++pos;
value.erase(pos);
}
out += value;
}
out += value;
}
bool CObjectNumber::set(const std::string& key, double value)
bool CObjectNumber::set(const std::string& key, sint64 value)
{
//H_AUTO(R2_CObjectNumber_set)
BOMB_IF(!key.empty(), "Try to set an element of a table on an object that is not a table", return false);
_Value = value;
m_IsInteger = true;
m_Value.Integer = value;
return true;
}
bool CObjectNumber::set(const std::string& key, double value)
{
//H_AUTO(R2_CObjectNumber_set)
BOMB_IF(!key.empty(), "Try to set an element of a table on an object that is not a table", return false);
m_IsInteger = false;
m_Value.Number = value;
return true;
}
bool CObjectNumber::set(const std::string& key, const std::string & value)
{
//H_AUTO(R2_CObjectNumber_set)
//XXX
BOMB_IF(!key.empty(), "Try to set an element of a table on an object that is not a table", return false);
NLMISC::fromString(value, _Value);
return true;
double num;
sint64 i;
if (NLMISC::fromString(value, i))
{
if (NLMISC::toString(i) == value)
{
m_IsInteger = true;
m_Value.Integer = i;
return true;
}
}
if (NLMISC::fromString(value, num))
{
m_IsInteger = false;
m_Value.Number = num;
return true;
}
return false;
}
double CObjectNumber::doToNumber() const { return _Value; }
CObject* CObjectNumber::clone() const
{
//H_AUTO(R2_CObjectNumber_clone)
CObjectNumber *result = new CObjectNumber(_Value);
CObjectNumber *result = m_IsInteger
? new CObjectNumber(m_Value.Integer)
: new CObjectNumber(m_Value.Number);
result->setGhost(getGhost());
return result;
}
bool CObjectNumber::doIsNumber() const { return true;}
bool CObjectNumber::doIsNumber() const { return !m_IsInteger || (sint64)getNumberValue() == m_Value.Integer;}
double CObjectNumber::doToNumber() const { return getNumberValue(); }
bool CObjectNumber::doIsInteger() const { return m_IsInteger || (double)getIntegerValue() == m_Value.Number;}
sint64 CObjectNumber::doToInteger() const { return getIntegerValue(); }
bool CObjectNumber::setObject(const std::string& /* key */, CObject* value)
{
//H_AUTO(R2_CObjectNumber_setObject)
BOMB_IF(!value->isNumber(), NLMISC::toString("Try to set an element of a type '%s' with a value of type '%s' on an object that is not a number", this->getTypeAsString(), value->getTypeAsString()), return false);
BOMB_IF(!value->isNumber() && !value->isInteger(), NLMISC::toString("Try to set an element of a type '%s' with a value of type '%s' on an object that is not a number", this->getTypeAsString(), value->getTypeAsString()), return false);
_Value = value->toNumber();
if (value->isInteger())
{
m_IsInteger = true;
m_Value.Integer = value->toInteger();
}
else
{
m_IsInteger = false;
m_Value.Number = value->toNumber();
}
setGhost(value->getGhost());
return true;
}
bool CObjectNumber::equal(const CObject* other) const
{
//H_AUTO(R2_CObjectNumber_equal)
if (!other || !other->isNumber()) return false;
if (!other) return false;
if (isInteger() && other->isInteger())
{
return (getIntegerValue() == other->toInteger());
}
if (!other->isNumber()) return false;
double value = getNumberValue();
double otherValue = other->toNumber();
if (_Value == otherValue) return true;
if (value == otherValue) return true;
// if difference between 2 values less than epsilon, we consider they are equals
return fabs(_Value - otherValue) <= std::numeric_limits<double>::epsilon();
}
//----------------------- CObjectInteger ----------------------------------------
CObjectInteger::CObjectInteger(sint64 value) : CObject(), _Value(value){}
const char *CObjectInteger::getTypeAsString() const
{
return "Integer";
return fabs(value - otherValue) <= std::numeric_limits<double>::epsilon();
}
void CObjectInteger::visitInternal(IObjectVisitor &visitor)
{
//H_AUTO(R2_CObjectInteger_visit)
visitor.visit(*this);
}
void CObjectInteger::inPlaceCopyTo(CObject &dest) const
{
//H_AUTO(R2_CObjectInteger_inPlaceCopyTo)
dest.inPlaceCopy(*this);
}
void CObjectInteger::inPlaceCopy(const CObjectInteger &src)
{
//H_AUTO(R2_CObjectInteger_inPlaceCopy)
_Value = src._Value;
setGhost(src.getGhost());
}
std::string CObjectInteger::doToString() const { return NLMISC::toString(_Value); }
void CObjectInteger::doSerialize(std::string& out, CSerializeContext& /* context */) const
{
//H_AUTO(R2_CObjectInteger_doSerialize)
nlassert(!getGhost());
out += NLMISC::toString(_Value);
}
bool CObjectInteger::set(const std::string& key, sint64 value)
{
//H_AUTO(R2_CObjectInteger_set)
BOMB_IF(!key.empty(), "Try to set an element of a table on an object that is not a table", return false);
_Value = value;
return true;
}
bool CObjectInteger::set(const std::string& key, const std::string & value)
{
//H_AUTO(R2_CObjectInteger_set)
//XXX
BOMB_IF(!key.empty(), "Try to set an element of a table on an object that is not a table", return false);
NLMISC::fromString(value, _Value);
return true;
}
sint64 CObjectInteger::doToInteger() const { return _Value; }
CObject* CObjectInteger::clone() const
{
//H_AUTO(R2_CObjectInteger_clone)
CObjectInteger *result = new CObjectInteger(_Value);
result->setGhost(getGhost());
return result;
}
bool CObjectInteger::doIsInteger() const { return true;}
bool CObjectInteger::setObject(const std::string& /* key */, CObject* value)
{
//H_AUTO(R2_CObjectInteger_setObject)
BOMB_IF(!value->isInteger(), NLMISC::toString("Try to set an element of a type '%s' with a value of type '%s' on an object that is not an integer", this->getTypeAsString(), value->getTypeAsString()), return false);
_Value = value->toInteger();
setGhost(value->getGhost());
return true;
}
bool CObjectInteger::equal(const CObject* other) const
{
//H_AUTO(R2_CObjectInteger_equal)
if (!other || !other->isInteger()) return false;
sint64 otherValue = other->toInteger();
return _Value == otherValue;
}
//----------------------- CObjectTable ----------------------------------------
@ -1686,7 +1644,7 @@ CObject* CObjectFactory::newBasic(const std::string & type)
}
else if (type == "Number")
{
return new CObjectNumber(0);
return new CObjectNumber((sint64)0);
}
else if (type == "Table")
{
@ -1976,15 +1934,10 @@ void CObjectNumber::dump(const std::string prefix, uint depth) const
{
//H_AUTO(R2_CObjectNumber_dump)
std::string result(depth * 4, ' ');
result += NLMISC::toString("%sNumber, ptr = 0x%p, value = %lf, ghost = %s", prefix.c_str(), this, _Value, _Ghost ? "true" : "false");
nlwarning(result.c_str());
}
void CObjectInteger::dump(const std::string prefix, uint depth) const
{
//H_AUTO(R2_CObjectInteger_dump)
std::string result(depth * 4, ' ');
result += NLMISC::toString("%sInteger, ptr = 0x%p, value = %" NL_I64 "d, ghost = %s", prefix.c_str(), this, _Value, _Ghost ? "true" : "false");
if (m_IsInteger)
result += NLMISC::toString("%sNumber, ptr = 0x%p, isNumber, value = %lf, ghost = %s", prefix.c_str(), this, m_Value.Integer, _Ghost ? "true" : "false");
else
result += NLMISC::toString("%sNumber, ptr = 0x%p, isInteger, value = %lf, ghost = %s", prefix.c_str(), this, m_Value.Number, _Ghost ? "true" : "false");
nlwarning(result.c_str());
}
@ -3330,13 +3283,13 @@ void CObjectSerializerImpl::serialImpl(NLMISC::IStream& stream, CObject*& data,
{
double value;
stream.serial(value);
data = serializer->Factory ? serializer->Factory->newBasic("Number") : new CObjectNumber(0);
data = serializer->Factory ? serializer->Factory->newBasic("Number") : new CObjectNumber((sint64)0);
((CObjectNumber *) data)->set("", value);
return;
}
case ObjectNumberZero:
{
data = serializer->Factory ? serializer->Factory->newBasic("Number") : new CObjectNumber(0);
data = serializer->Factory ? serializer->Factory->newBasic("Number") : new CObjectNumber((sint64)0);
((CObjectNumber *) data)->set("", 0.0);
return;
}
@ -3344,8 +3297,8 @@ void CObjectSerializerImpl::serialImpl(NLMISC::IStream& stream, CObject*& data,
{
sint32 value;
stream.serial(value);
data = serializer->Factory ? serializer->Factory->newBasic("Number") : new CObjectNumber(0);
((CObjectNumber *) data)->set("", value);
data = serializer->Factory ? serializer->Factory->newBasic("Number") : new CObjectNumber((sint64)0);
((CObjectNumber *) data)->set("", (sint64)value);
return;
}
@ -3353,8 +3306,8 @@ void CObjectSerializerImpl::serialImpl(NLMISC::IStream& stream, CObject*& data,
{
uint32 value;
stream.serial(value);
data = serializer->Factory ? serializer->Factory->newBasic("Number") : new CObjectNumber(0);
((CObjectNumber *) data)->set("", value);
data = serializer->Factory ? serializer->Factory->newBasic("Number") : new CObjectNumber((sint64)0);
((CObjectNumber *) data)->set("", (sint64)value);
return;
}
@ -3362,8 +3315,8 @@ void CObjectSerializerImpl::serialImpl(NLMISC::IStream& stream, CObject*& data,
{
sint16 value;
stream.serial(value);
data = serializer->Factory ? serializer->Factory->newBasic("Number") : new CObjectNumber(0);
((CObjectNumber *) data)->set("", value);
data = serializer->Factory ? serializer->Factory->newBasic("Number") : new CObjectNumber((sint64)0);
((CObjectNumber *) data)->set("", (sint64)value);
return;
}
@ -3371,8 +3324,8 @@ void CObjectSerializerImpl::serialImpl(NLMISC::IStream& stream, CObject*& data,
{
uint16 value;
stream.serial(value);
data = serializer->Factory ? serializer->Factory->newBasic("Number") : new CObjectNumber(0);
((CObjectNumber *) data)->set("", value);
data = serializer->Factory ? serializer->Factory->newBasic("Number") : new CObjectNumber((sint64)0);
((CObjectNumber *) data)->set("", (sint64)value);
return;
}
@ -3380,8 +3333,8 @@ void CObjectSerializerImpl::serialImpl(NLMISC::IStream& stream, CObject*& data,
{
sint8 value;
stream.serial(value);
data = serializer->Factory ? serializer->Factory->newBasic("Number") : new CObjectNumber(0);
((CObjectNumber *) data)->set("", value);
data = serializer->Factory ? serializer->Factory->newBasic("Number") : new CObjectNumber((sint64)0);
((CObjectNumber *) data)->set("", (sint64)value);
return;
}
@ -3389,8 +3342,8 @@ void CObjectSerializerImpl::serialImpl(NLMISC::IStream& stream, CObject*& data,
{
uint8 value;
stream.serial(value);
data = serializer->Factory ? serializer->Factory->newBasic("Number") : new CObjectNumber(0);
((CObjectNumber *) data)->set("", value);
data = serializer->Factory ? serializer->Factory->newBasic("Number") : new CObjectNumber((sint64)0);
((CObjectNumber *) data)->set("", (sint64)value);
return;
}
// Do not remove this or it would be impossible to load old session
@ -3398,8 +3351,8 @@ void CObjectSerializerImpl::serialImpl(NLMISC::IStream& stream, CObject*& data,
{
float value;
stream.serial(value);
data = serializer->Factory ? serializer->Factory->newBasic("Number") : new CObjectNumber(0);
((CObjectNumber *) data)->set("", value);
data = serializer->Factory ? serializer->Factory->newBasic("Number") : new CObjectNumber((sint64)0);
((CObjectNumber *) data)->set("", (double)value);
return;
}
@ -3407,7 +3360,7 @@ void CObjectSerializerImpl::serialImpl(NLMISC::IStream& stream, CObject*& data,
{
double value;
stream.serial(value);
data = serializer->Factory ? serializer->Factory->newBasic("Number") : new CObjectNumber(0);
data = serializer->Factory ? serializer->Factory->newBasic("Number") : new CObjectNumber((sint64)0);
((CObjectNumber *) data)->set("", value);
return;
}

@ -206,7 +206,6 @@ public:
virtual void inPlaceCopyTo(CObject &dest) const = 0;
virtual void inPlaceCopy(const CObjectString &src);
virtual void inPlaceCopy(const CObjectNumber &src);
virtual void inPlaceCopy(const CObjectInteger &src);
virtual void inPlaceCopy(const CObjectTable &src);
protected:
void copyMismatchMsg(const CObject &src);
@ -287,78 +286,51 @@ class CObjectNumber : public CObject
public:
explicit CObjectNumber(double value);
explicit CObjectNumber(sint64 value);
virtual const char *getTypeAsString() const;
virtual const char *getTypeAsString() const NL_OVERRIDE;
virtual bool set(const std::string& key, double value);
virtual bool set(const std::string& key, const std::string&value);
virtual bool set(const std::string& key, sint64 value) NL_OVERRIDE;
virtual bool set(const std::string& key, double value) NL_OVERRIDE;
virtual bool set(const std::string& key, const std::string&value) NL_OVERRIDE;
virtual bool setObject(const std::string& key, CObject* value);
virtual bool setObject(const std::string& key, CObject* value) NL_OVERRIDE;
virtual CObject* clone() const;
virtual CObject* clone() const NL_OVERRIDE;
double getValue() const { return _Value; }
double getNumberValue() const { return m_IsInteger ? m_Value.Integer : m_Value.Number; }
sint64 getIntegerValue() const { return m_IsInteger ? m_Value.Integer : m_Value.Number; }
virtual void dump(const std::string prefix = "", uint depth = 0) const;
virtual void dump(const std::string prefix = "", uint depth = 0) const NL_OVERRIDE;
virtual bool equal(const CObject* other) const;
virtual bool equal(const CObject* other) const NL_OVERRIDE;
protected:
virtual void doSerialize(std::string& out, CSerializeContext& context) const;
virtual bool doIsNumber() const;
virtual double doToNumber() const;
virtual std::string doToString() const;
virtual void inPlaceCopyTo(CObject &dest) const;
virtual void inPlaceCopy(const CObjectNumber &src);
virtual void doSerialize(std::string& out, CSerializeContext& context) const NL_OVERRIDE;
virtual void visitInternal(IObjectVisitor &visitor);
virtual bool doIsNumber() const NL_OVERRIDE;
private:
double _Value;
virtual double doToNumber() const NL_OVERRIDE;
};
virtual bool doIsInteger() const NL_OVERRIDE;
class CObjectInteger : public CObject
{
virtual sint64 doToInteger() const NL_OVERRIDE;
public:
explicit CObjectInteger(sint64 value);
virtual std::string doToString() const NL_OVERRIDE;
virtual const char *getTypeAsString() const;
virtual void inPlaceCopyTo(CObject &dest) const NL_OVERRIDE;
virtual void inPlaceCopy(const CObjectNumber &src) NL_OVERRIDE;
virtual bool set(const std::string& key, sint64 value);
virtual bool set(const std::string& key, const std::string &value);
virtual bool setObject(const std::string& key, CObject* value);
virtual CObject* clone() const;
sint64 getValue() const { return _Value; }
virtual void dump(const std::string prefix = "", uint depth = 0) const;
virtual bool equal(const CObject* other) const;
protected:
virtual void doSerialize(std::string& out, CSerializeContext& context) const;
virtual bool doIsInteger() const;
virtual sint64 doToInteger() const;
virtual std::string doToString() const;
virtual void inPlaceCopyTo(CObject &dest) const;
virtual void inPlaceCopy(const CObjectInteger &src);
virtual void visitInternal(IObjectVisitor &visitor);
virtual void visitInternal(IObjectVisitor &visitor) NL_OVERRIDE;
private:
sint64 _Value;
bool m_IsInteger;
union
{
double Number;
sint64 Integer;
} m_Value;
};
class CObjectTable: public CObject

Loading…
Cancel
Save