Merge branch 'fixes' into atys
commit
0fbbf10361
@ -1,74 +0,0 @@
|
||||
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
|
||||
// Copyright (C) 2010 Winch Gate Property Limited
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
|
||||
#ifndef XML_MACROS_H
|
||||
#define XML_MACROS_H
|
||||
|
||||
//
|
||||
// xmlNodePtr cur;
|
||||
// CXMLAutoPtr prop;
|
||||
//
|
||||
// sint i;
|
||||
// XML_READ_SINT(cur, "prop_name", i, -1);
|
||||
//
|
||||
|
||||
#define XML_READ_UINT(node, name, var, def) { \
|
||||
uint tmp; \
|
||||
prop = (char *) xmlGetProp(node, (xmlChar*)name); \
|
||||
if (prop && fromString((const char*)prop, tmp)) \
|
||||
var = tmp; \
|
||||
else \
|
||||
var = def; \
|
||||
}
|
||||
|
||||
#define XML_READ_SINT(node, name, var, def) { \
|
||||
sint tmp; \
|
||||
prop = (char *) xmlGetProp(node, (xmlChar*)name); \
|
||||
if (prop && fromString((const char*)prop, tmp)) \
|
||||
var = tmp; \
|
||||
else \
|
||||
var = def; \
|
||||
}
|
||||
|
||||
#define XML_READ_BOOL(node, name, var, def) { \
|
||||
prop = (char *) xmlGetProp(node, (xmlChar*)name); \
|
||||
if (prop) \
|
||||
var = NLMISC::toBool((const char*)prop); \
|
||||
else \
|
||||
var = def; \
|
||||
}
|
||||
|
||||
#define XML_READ_COLOR(node, name, var, def) { \
|
||||
NLMISC::CRGBA tmp; \
|
||||
prop = (char *) xmlGetProp(node, (xmlChar*)name); \
|
||||
if (prop && fromString((const char*)prop, tmp)) \
|
||||
var = tmp; \
|
||||
else \
|
||||
var = def; \
|
||||
}
|
||||
|
||||
#define XML_READ_STRING(node, name, var, def) { \
|
||||
prop = (char *) xmlGetProp(node, (xmlChar*)name); \
|
||||
if (prop) \
|
||||
var = (const char*)prop; \
|
||||
else \
|
||||
var = def; \
|
||||
}
|
||||
|
||||
#endif // XML_MACROS_H
|
||||
|
@ -0,0 +1,83 @@
|
||||
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
|
||||
// Copyright (C) 2010-2019 Winch Gate Property Limited
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef CL_CSS_BACKGROUND_H
|
||||
#define CL_CSS_BACKGROUND_H
|
||||
|
||||
#include "nel/misc/types_nl.h"
|
||||
#include "nel/misc/rgba.h"
|
||||
#include "nel/gui/css_types.h"
|
||||
#include "nel/gui/css_length.h"
|
||||
|
||||
namespace NLGUI
|
||||
{
|
||||
/**
|
||||
* \brief CSS background info
|
||||
* \date 2021-07-02 11:36 GMT
|
||||
* \author Meelis Mägi (Nimetu)
|
||||
*/
|
||||
class CSSBackground
|
||||
{
|
||||
public:
|
||||
CSSBackground()
|
||||
:color(NLMISC::CRGBA::Transparent),
|
||||
repeatX(CSS_VALUE_REPEAT), repeatY(CSS_VALUE_REPEAT), attachment(CSS_VALUE_SCROLL),
|
||||
xAnchor(CSS_VALUE_LEFT), yAnchor(CSS_VALUE_TOP),
|
||||
clip(CSS_VALUE_BORDER_BOX), origin(CSS_VALUE_PADDING_BOX), size(CSS_VALUE_AUTO)
|
||||
{}
|
||||
|
||||
void setImage(const std::string &value);
|
||||
void setPosition(const std::string &value);
|
||||
void setSize(const std::string &value);
|
||||
void setRepeat(const std::string &value);
|
||||
void setOrigin(const std::string &value);
|
||||
void setClip(const std::string &value);
|
||||
void setAttachment(const std::string &value);
|
||||
void setColor(const std::string &value);
|
||||
|
||||
public:
|
||||
// TODO: only final layer has color
|
||||
NLMISC::CRGBA color;
|
||||
std::string image;
|
||||
|
||||
CSSValueType repeatX;
|
||||
CSSValueType repeatY;
|
||||
CSSValueType attachment;
|
||||
|
||||
CSSValueType xAnchor;
|
||||
CSSValueType yAnchor;
|
||||
CSSLength xPosition;
|
||||
CSSLength yPosition;
|
||||
|
||||
CSSValueType clip;
|
||||
CSSValueType origin;
|
||||
|
||||
CSSValueType size;
|
||||
CSSLength width;
|
||||
CSSLength height;
|
||||
|
||||
private:
|
||||
void positionFromOne(const std::vector<std::string> &parts);
|
||||
void positionFromTwo(const std::vector<std::string> &parts);
|
||||
void positionFromThree(const std::vector<std::string> &parts);
|
||||
void positionFromFour(const std::vector<std::string> &parts);
|
||||
};
|
||||
|
||||
}//namespace
|
||||
|
||||
#endif // CL_CSS_BACKGROUND_H
|
||||
|
||||
|
@ -0,0 +1,193 @@
|
||||
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
|
||||
// Copyright (C) 2010-2019 Winch Gate Property Limited
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
|
||||
#ifndef NL_CSS_BACKGROUND_RENDERER_H
|
||||
#define NL_CSS_BACKGROUND_RENDERER_H
|
||||
|
||||
#include "nel/misc/types_nl.h"
|
||||
#include "nel/misc/rgba.h"
|
||||
#include "nel/misc/geom_ext.h"
|
||||
#include "nel/gui/css_types.h"
|
||||
#include "nel/gui/css_background.h"
|
||||
|
||||
namespace NLGUI
|
||||
{
|
||||
class CInterfaceElement;
|
||||
|
||||
/**
|
||||
* \brief Border renderer for GUI classes
|
||||
* \date 2021-06-29 15:17 GMT
|
||||
* \author Meelis Mägi (Nimetu)
|
||||
*/
|
||||
class CSSBackgroundRenderer
|
||||
{
|
||||
public:
|
||||
// alpha value from parent
|
||||
uint8 CurrentAlpha;
|
||||
|
||||
// TODO: should be moved to CSSBackground
|
||||
sint32 TextureId;
|
||||
|
||||
public:
|
||||
CSSBackgroundRenderer();
|
||||
~CSSBackgroundRenderer();
|
||||
|
||||
// return true if no background is set
|
||||
bool isEmpty() const
|
||||
{
|
||||
return m_Background.image.empty() && m_Background.color.A == 0;
|
||||
}
|
||||
|
||||
void setModulateGlobalColor(bool m) { m_ModulateGlobalColor = m; }
|
||||
|
||||
void updateCoords();
|
||||
void invalidateCoords() { m_Dirty = true; }
|
||||
void invalidateContent() { m_Dirty = true; };
|
||||
|
||||
void clear();
|
||||
void setBackground(const CSSBackground &bg);
|
||||
|
||||
// helper function to change background image
|
||||
void setImage(const std::string &bgtex);
|
||||
void setImageRepeat(bool b);
|
||||
void setImageCover(bool b);
|
||||
|
||||
// helper function to change background color
|
||||
void setColor(const NLMISC::CRGBA &color)
|
||||
{
|
||||
m_Dirty = true;
|
||||
m_Background.color = color;
|
||||
}
|
||||
|
||||
NLMISC::CRGBA getColor() const
|
||||
{
|
||||
return m_Background.color;
|
||||
}
|
||||
|
||||
// override painting area to be at least the size of viewport (ie, <html> background)
|
||||
void setFillViewport(bool b) {
|
||||
m_Dirty = true;
|
||||
m_FillViewport = b;
|
||||
}
|
||||
|
||||
void setViewport(CInterfaceElement *root)
|
||||
{
|
||||
m_Dirty = true;
|
||||
m_Viewport = root;
|
||||
}
|
||||
|
||||
void setBorderArea(sint32 x, sint32 y, sint32 w, sint32 h)
|
||||
{
|
||||
m_Dirty = true;
|
||||
m_BorderX = x;
|
||||
m_BorderY = y;
|
||||
m_BorderW = w;
|
||||
m_BorderH = h;
|
||||
}
|
||||
|
||||
void setPaddingArea(sint32 x, sint32 y, sint32 w, sint32 h)
|
||||
{
|
||||
m_Dirty = true;
|
||||
m_PaddingX = x;
|
||||
m_PaddingY = y;
|
||||
m_PaddingW = w;
|
||||
m_PaddingH = h;
|
||||
}
|
||||
|
||||
void setContentArea(sint32 x, sint32 y, sint32 w, sint32 h)
|
||||
{
|
||||
m_Dirty = true;
|
||||
m_ContentX = x;
|
||||
m_ContentY = y;
|
||||
m_ContentW = w;
|
||||
m_ContentH = h;
|
||||
}
|
||||
|
||||
// sizes for em, rem units
|
||||
void setFontSize(float rootFontSize, float fontSize)
|
||||
{
|
||||
m_Dirty = true;
|
||||
m_RootFontSize = rootFontSize;
|
||||
m_FontSize = fontSize;
|
||||
}
|
||||
|
||||
void draw();
|
||||
|
||||
private:
|
||||
sint32 m_BorderX, m_BorderY, m_BorderW, m_BorderH;
|
||||
sint32 m_PaddingX, m_PaddingY, m_PaddingW, m_PaddingH;
|
||||
sint32 m_ContentX, m_ContentY, m_ContentW, m_ContentH;
|
||||
|
||||
// font size for 'rem'
|
||||
float m_RootFontSize;
|
||||
|
||||
// font size for 'em'
|
||||
float m_FontSize;
|
||||
|
||||
// viewport element for vw,wh,vmin,vmax
|
||||
CInterfaceElement* m_Viewport;
|
||||
|
||||
struct SDrawQueue
|
||||
{
|
||||
sint32 TextureId;
|
||||
NLMISC::CQuadUV Quad;
|
||||
NLMISC::CRGBA Color;
|
||||
};
|
||||
std::vector<SDrawQueue> m_DrawQueue;
|
||||
|
||||
const sint8 m_RenderLayer;
|
||||
bool m_ModulateGlobalColor;
|
||||
// if true, painting area returns area at least the size of viewport (ie, <html> background)
|
||||
bool m_FillViewport;
|
||||
|
||||
// if true, then updateCoords() is called from draw()
|
||||
bool m_Dirty;
|
||||
|
||||
CSSBackground m_Background;
|
||||
|
||||
// get clip area based on background-clip
|
||||
void getPaintingArea(const CSSBackground &bg, sint32 &areaX, sint32 &areaY, sint32 &areaW, sint32 &areaH) const;
|
||||
|
||||
// get positioning area based on background-origin
|
||||
void getPositioningArea(const CSSBackground &bg, sint32 &areaX, sint32 &areaY, sint32 &areaW, sint32 &areaH) const;
|
||||
|
||||
// calculate image size based on background-size
|
||||
void calculateSize(const CSSBackground &bg, sint32 &texW, sint32 &texH) const;
|
||||
|
||||
// calculate image position based on background-position
|
||||
void calculatePosition(const CSSBackground &bg, sint32 &texX, sint32 &texY, sint32 &texW, sint32 &texH) const;
|
||||
|
||||
// calculate image tile position, size, count, and spacing based on background-repeat
|
||||
void calculateTiles(const CSSBackground &bg, sint32 &texX, sint32 &texY, sint32 &texW, sint32 &texH, sint32 &tilesX, sint32 &tilesY, sint32 &spacingX, sint32 &spacingY) const;
|
||||
|
||||
// position, size, and count for first tile to cover an area
|
||||
void getImageTile(sint32 &tilePos, sint32 &tileSize, sint32 &spacing, sint32 &tiles, sint32 areaPos, sint32 areaSize, CSSValueType repeat) const;
|
||||
|
||||
// push background color to draw queue
|
||||
void buildColorQuads(const CSSBackground &bg);
|
||||
|
||||
// push background image to draw quque
|
||||
void buildImageQuads(const CSSBackground &bg, sint32 textureId);
|
||||
|
||||
}; // CSSBackgroundRenderer
|
||||
|
||||
}//namespace
|
||||
|
||||
#endif // NL_CSS_BACKGROUND_RENDERER_H
|
||||
|
||||
|
@ -0,0 +1,72 @@
|
||||
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
|
||||
// Copyright (C) 2010-2019 Winch Gate Property Limited
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef CL_CSS_BORDER_H
|
||||
#define CL_CSS_BORDER_H
|
||||
|
||||
#include "nel/misc/types_nl.h"
|
||||
#include "nel/misc/rgba.h"
|
||||
#include "nel/gui/css_types.h"
|
||||
#include "nel/gui/css_length.h"
|
||||
|
||||
namespace NLGUI
|
||||
{
|
||||
/**
|
||||
* \brief CSS border info
|
||||
* \date 2021-07-23 09:51 GMT
|
||||
* \author Meelis Mägi (Nimetu)
|
||||
*/
|
||||
class CSSBorder
|
||||
{
|
||||
public:
|
||||
CSSBorder()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
CSSBorder(uint width, CSSLineStyle style, NLMISC::CRGBA color)
|
||||
{
|
||||
set(width, style, color);
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
set(CSS_LINE_WIDTH_MEDIUM, CSS_LINE_STYLE_NONE, NLMISC::CRGBA::Transparent);
|
||||
}
|
||||
|
||||
void set(uint width, CSSLineStyle style, NLMISC::CRGBA color)
|
||||
{
|
||||
Width.setFloatValue(width, "px");
|
||||
Style = style;
|
||||
Color = color;
|
||||
}
|
||||
|
||||
bool empty() const
|
||||
{
|
||||
return Style == CSS_LINE_STYLE_NONE || Style == CSS_LINE_STYLE_HIDDEN
|
||||
|| Width.getFloat() == 0;
|
||||
}
|
||||
|
||||
CSSLength Width;
|
||||
CSSLineStyle Style;
|
||||
NLMISC::CRGBA Color;
|
||||
};
|
||||
|
||||
}//namespace
|
||||
|
||||
#endif // CL_CSS_BORDER_H
|
||||
|
||||
|
@ -0,0 +1,76 @@
|
||||
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
|
||||
// Copyright (C) 2010-2021 Winch Gate Property Limited
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef CL_CSS_LENGTH_H
|
||||
#define CL_CSS_LENGTH_H
|
||||
|
||||
#include "nel/misc/types_nl.h"
|
||||
#include "nel/gui/css_types.h"
|
||||
|
||||
namespace NLGUI
|
||||
{
|
||||
/**
|
||||
* \brief CSS types used in GUI classes
|
||||
* \date 2021-07-02 11:36 GMT
|
||||
* \author Meelis Mägi (Nimetu)
|
||||
*/
|
||||
|
||||
class CSSLength
|
||||
{
|
||||
public:
|
||||
enum Kind {
|
||||
Auto, Relative, Fixed
|
||||
};
|
||||
|
||||
CSSLength(float value = 0, CSSUnitType unit = CSS_UNIT_NONE, Kind kind = Auto)
|
||||
: m_Value(value), m_Unit(unit), m_Kind(Auto)
|
||||
{}
|
||||
|
||||
void setAuto() { m_Kind = Auto; }
|
||||
bool parseValue(const std::string &value, bool allowPercent = true, bool allowNegative = false);
|
||||
void setFloatValue(float f, const std::string &unit);
|
||||
|
||||
float getValue() const;
|
||||
float getFloat() const { return m_Value; }
|
||||
|
||||
bool isPercent() const { return m_Unit == CSS_UNIT_PERCENT; }
|
||||
|
||||
bool isAuto() const { return m_Kind == Auto; }
|
||||
bool isRelative() const { return m_Kind == Relative; }
|
||||
|
||||
// % uses relValue
|
||||
// em uses emSize
|
||||
// rem uses remSize
|
||||
// vw,vh,vi,vb,vmin,vmax uses vwSize/vhSize
|
||||
float calculate(uint32 relValue, uint32 emSize, uint32 remSize, uint32 vwSize, uint32 whSize) const;
|
||||
|
||||
CSSUnitType getUnit() const { return m_Unit; }
|
||||
|
||||
std::string toString() const;
|
||||
|
||||
private:
|
||||
void setUnit(const std::string &unit);
|
||||
|
||||
float m_Value;
|
||||
CSSUnitType m_Unit;
|
||||
Kind m_Kind;
|
||||
};
|
||||
|
||||
}//namespace
|
||||
|
||||
#endif // CL_CSS_LENGTH_H
|
||||
|
||||
|
@ -0,0 +1,83 @@
|
||||
// NeL - MMORPG Framework <https://wiki.ryzom.dev/>
|
||||
// Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef NLMISC_DEEP_PTR_H
|
||||
#define NLMISC_DEEP_PTR_H
|
||||
|
||||
#include <nel/misc/types_nl.h>
|
||||
|
||||
namespace NLMISC {
|
||||
|
||||
/// Pointer template with deep copy and move semantics
|
||||
template<class T>
|
||||
class CDeepPtr
|
||||
{
|
||||
public:
|
||||
NL_FORCE_INLINE CDeepPtr() : m(NULL) { } //< Null
|
||||
NL_FORCE_INLINE ~CDeepPtr() { delete m; }
|
||||
|
||||
NL_FORCE_INLINE CDeepPtr(const CDeepPtr &p) : m(p.m ? new T(*p) : NULL) { } //< Copy operator
|
||||
NL_FORCE_INLINE CDeepPtr &operator=(const CDeepPtr &p) { if (p.m) { if (!m) m = new T(*p); else *m = *p; } else { delete m; m = NULL; } return *this; } //< Copy operator
|
||||
|
||||
#ifdef NL_CPP14
|
||||
NL_FORCE_INLINE CDeepPtr(CDeepPtr &&p) noexcept : m(p.m) { p.m = NULL; } //< Move operator
|
||||
NL_FORCE_INLINE CDeepPtr &operator=(CDeepPtr &&p) noexcept { delete m; m = p.m; p.m = NULL; return *this; } //< Move operator
|
||||
#endif
|
||||
|
||||
NL_FORCE_INLINE CDeepPtr(T *p) : m(p) { } //< Initializer
|
||||
NL_FORCE_INLINE CDeepPtr &operator=(T *p) { delete m; m = p; return *this; } //< Initializer
|
||||
|
||||
NL_FORCE_INLINE bool operator==(const CDeepPtr &p) const { return /* (m == p.m) || */ (m && p.m && *m == *p); }
|
||||
NL_FORCE_INLINE bool operator!=(const CDeepPtr &p) const { return !(*this == p); }
|
||||
|
||||
NL_FORCE_INLINE bool operator==(const T *p) const { return (m == p) || (m && p && *m == *p); }
|
||||
NL_FORCE_INLINE bool operator!=(const T *p) const { return !(*this == p); }
|
||||
|
||||
NL_FORCE_INLINE bool operator==(const T &p) const { return (m == &p) || (m && *m == p); }
|
||||
NL_FORCE_INLINE bool operator!=(const T &p) const { return !(*this == p); }
|
||||
|
||||
NL_FORCE_INLINE bool operator==(long int p) const { return (*this == (const T *)(ptrdiff_t)p); } //< == NULL
|
||||
NL_FORCE_INLINE bool operator!=(long int p) const { return (*this != (const T *)(ptrdiff_t)p); } //< != NULL
|
||||
|
||||
NL_FORCE_INLINE bool operator==(int p) const { return (*this == (const T *)(ptrdiff_t)p); } //< == 0
|
||||
NL_FORCE_INLINE bool operator!=(int p) const { return (*this != (const T *)(ptrdiff_t)p); } //< != 0
|
||||
|
||||
#ifdef NL_CPP14
|
||||
NL_FORCE_INLINE bool operator==(nullptr_t p) const { return (*this == (const T *)(ptrdiff_t)p); } //< == nullptr
|
||||
NL_FORCE_INLINE bool operator!=(nullptr_t p) const { return (*this != (const T *)(ptrdiff_t)p); } //< != nullptr
|
||||
#endif
|
||||
|
||||
NL_FORCE_INLINE T &operator*() { return *m; }
|
||||
NL_FORCE_INLINE const T &operator*() const { return *m; }
|
||||
NL_FORCE_INLINE T *operator->() { return m; }
|
||||
NL_FORCE_INLINE const T *operator->() const { return m; }
|
||||
|
||||
NL_FORCE_INLINE operator bool() const { return m; }
|
||||
NL_FORCE_INLINE bool operator!() const { return !m; }
|
||||
|
||||
NL_FORCE_INLINE T *ptr() { return m; }
|
||||
NL_FORCE_INLINE const T *ptr() const { return m; }
|
||||
|
||||
private:
|
||||
T *m;
|
||||
|
||||
};
|
||||
|
||||
} /* namespace NLMISC */
|
||||
|
||||
#endif /* #ifndef NLMISC_DEEP_PTR_H */
|
||||
|
||||
/* end of file */
|
@ -0,0 +1,131 @@
|
||||
// NeL - MMORPG Framework <https://wiki.ryzom.dev/>
|
||||
// Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef NLMISC_STRING_VIEW_H
|
||||
#define NLMISC_STRING_VIEW_H
|
||||
|
||||
#include <nel/misc/types_nl.h>
|
||||
#include <string>
|
||||
|
||||
#ifdef NL_CPP14
|
||||
using namespace std::string_literals;
|
||||
#ifdef NL_CPP17
|
||||
#include <string_view>
|
||||
using namespace std::string_view_literals;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef NL_CPP14
|
||||
/// Obtain an std::string from a string literal.
|
||||
#define nlstr(strLit) (strLit##s)
|
||||
#else
|
||||
/// Obtain an std::string from a string literal.
|
||||
#define nlstr(strLit) (std::string(strLit))
|
||||
#endif
|
||||
|
||||
#ifdef NL_CPP17
|
||||
/// Obtain a string view from a string literal.
|
||||
#define nlsv(strLit) (strLit##sv)
|
||||
/// Obtain an std::string from a string view.
|
||||
#define nlsvs(strView) (std::string(strView))
|
||||
#else
|
||||
/// Obtain a string view from a string literal.
|
||||
#define nlsv(strLit) (CStringView(strLit, ::strlen(strLit)))
|
||||
/// Obtain an std::string from a string view.
|
||||
#define nlsvs(strView) (std::string(strView.data(), strView.size()))
|
||||
#endif
|
||||
|
||||
/// Obtain a temporary C-string from a string view. Use directly in argument, do not store.
|
||||
#define nlsvc(strView) ((strView.data()[strView.size()]) ? nlsvs(strView).c_str() : strView.data())
|
||||
|
||||
namespace NLMISC {
|
||||
|
||||
/// String view literals allow bypassing allocation and strlen calls.
|
||||
/// CStringView is a 100% drop-in replacement for (const char *str, size_t len) tuples. It's a non-owning reference.
|
||||
/// Always use `CStringView` where previously `const std::string &` would have been used. It avoids accidental copy.
|
||||
/// Gotcha: CStringView doesn't need to end with \0, so there's no guarantee with functions that expect \0 terminated strings,
|
||||
/// use the `nlsvc` macro to get a temporary C-string from a CStringView.
|
||||
/// Use the `nlsv` macro to get a CStringView from a string literal.
|
||||
/// Use the `nlstr` macro to get an std::string from a string literal.
|
||||
/// Use the `nlsvs` macro to get an std::string from a CStringView.
|
||||
#ifdef NL_CPP17
|
||||
typedef std::string_view CStringView;
|
||||
#else
|
||||
class CStringView
|
||||
{
|
||||
public:
|
||||
CStringView(const std::string &str) : m_Str(&str[0]), m_Len(str.size()) {}
|
||||
CStringView(const char *const str, const size_t len) : m_Str(str), m_Len(len) {}
|
||||
CStringView(const char *const str) : m_Str(str), m_Len(sizeof(str)) {}
|
||||
|
||||
inline const char *data() const { return m_Str; }
|
||||
inline size_t length() const { return m_Len; }
|
||||
inline size_t size() const { return m_Len; }
|
||||
|
||||
inline CStringView substr(const size_t offset, const size_t count = -1) { return CStringView(m_Str + offset, std::min(m_Len - offset, count)); }
|
||||
|
||||
inline bool operator==(const CStringView o) { if (m_Len != o.m_Len) return false; return memcmp(m_Str, o.m_Str, m_Len) == 0; }
|
||||
inline bool operator!=(const CStringView o) { if (m_Len != o.m_Len) return true; return memcmp(m_Str, o.m_Str, m_Len) != 0; }
|
||||
|
||||
struct const_iterator
|
||||
{
|
||||
public:
|
||||
const_iterator() : m_Addr(NULL) { }
|
||||
|
||||
inline void operator++()
|
||||
{
|
||||
++m_Addr;
|
||||
}
|
||||
inline void operator+=(ptrdiff_t v)
|
||||
{
|
||||
m_Addr += v;
|
||||
}
|
||||
inline void operator--()
|
||||
{
|
||||
--m_Addr;
|
||||
}
|
||||
inline void operator-=(ptrdiff_t v)
|
||||
{
|
||||
m_Addr -= v;
|
||||
}
|
||||
inline bool operator!=(const const_iterator &o) const { return m_Addr != o.m_Addr; }
|
||||
inline bool operator==(const const_iterator &o) const { return m_Addr == o.m_Addr; }
|
||||
inline const char &operator*() const { return *m_Addr; }
|
||||
|
||||
private:
|
||||
friend class CStringView;
|
||||
inline const_iterator(const char *addr) : m_Addr(addr) {}
|
||||
const char *m_Addr;
|
||||
|
||||
};
|
||||
|
||||
typedef const_iterator iterator;
|
||||
|
||||
iterator begin() const { return iterator(m_Str); }
|
||||
inline iterator end() const { return iterator(m_Str + m_Len); }
|
||||
|
||||
private:
|
||||
const char *m_Str;
|
||||
size_t m_Len;
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#endif /* #ifndef NLMISC_STRING_VIEW_H */
|
||||
|
||||
/* end of file */
|
@ -0,0 +1,178 @@
|
||||
// NeL - MMORPG Framework <https://wiki.ryzom.dev/>
|
||||
// Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef NLMISC_UTF_STRING_VIEW_H
|
||||
#define NLMISC_UTF_STRING_VIEW_H
|
||||
|
||||
#include <nel/misc/types_nl.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <nel/misc/string_view.h>
|
||||
#include <nel/misc/ucstring.h>
|
||||
|
||||
namespace NLMISC {
|
||||
|
||||
class IStream;
|
||||
|
||||
/// String view for UTF-8 and UTF-32 iteration as 32-bit codepoints.
|
||||
/// This string view keeps the string as a reference, it does not make a copy.
|
||||
/// Only use this for iterating a string's codepoints.
|
||||
/// String must be NUL terminated, but its size may specify a substring.
|
||||
class CUtfStringView
|
||||
{
|
||||
public:
|
||||
inline CUtfStringView() : m_Str(NULL), m_Size(0), m_Iterator(utf32Iterator) {}
|
||||
|
||||
inline CUtfStringView(const std::string &utf8Str) : m_Str(utf8Str.c_str()), m_Size(utf8Str.size()), m_Iterator(utf8Iterator) {}
|
||||
inline CUtfStringView(const char *utf8Str) : m_Str(utf8Str), m_Size(strlen(utf8Str)), m_Iterator(utf8Iterator) {}
|
||||
inline CUtfStringView(const char *utf8Str, size_t len): m_Str(utf8Str), m_Size(len), m_Iterator(utf8Iterator)
|
||||
{
|
||||
nlassert(len <= strlen(utf8Str));
|
||||
}
|
||||
|
||||
inline CUtfStringView(CStringView utf8Str) : m_Str(utf8Str.data()), m_Size(utf8Str.size()), m_Iterator(utf8Iterator) {}
|
||||
|
||||
#if defined(NL_OS_WINDOWS)
|
||||
inline CUtfStringView(const wchar_t *utf16Str) : m_Str(utf16Str), m_Size(wcslen(utf16Str)), m_Iterator(utf16Iterator) {}
|
||||
inline CUtfStringView(const wchar_t *utf16Str, size_t len): m_Str(utf16Str), m_Size(len), m_Iterator(utf16Iterator)
|
||||
{
|
||||
nlassert(len <= wcslen(utf16Str));
|
||||
}
|
||||
#else
|
||||
inline CUtfStringView(const wchar_t *utf32Str) : m_Str(utf32Str), m_Size(wcslen(utf32Str)), m_Iterator(utf32Iterator) {}
|
||||
inline CUtfStringView(const wchar_t *utf32Str, size_t len): m_Str(utf32Str), m_Size(len), m_Iterator(utf32Iterator)
|
||||
{
|
||||
nlassert(len <= wcslen(utf32Str));
|
||||
}
|
||||
#endif
|
||||
|
||||
inline CUtfStringView(const ucstring &utf16Str) : m_Str(utf16Str.c_str()), m_Size(utf16Str.size() << 1), m_Iterator(utf16Iterator) {}
|
||||
inline CUtfStringView(const ucchar *utf16Str) : m_Str(utf16Str), m_Size(strlen((const char *)utf16Str) & (ptrdiff_t)(-2)), m_Iterator(utf16Iterator) {}
|
||||
inline CUtfStringView(const ::u32string &utf32Str) : m_Str(utf32Str.c_str()), m_Size(utf32Str.size() << 2), m_Iterator(utf32Iterator) {}
|
||||
|
||||
std::string toUtf8(bool reEncode = false) const; // Makes a copy
|
||||
ucstring toUtf16(bool reEncode = false) const; // Makes a copy
|
||||
::u32string toUtf32() const; // Makes a copy
|
||||
|
||||
std::wstring toWide() const; // Platform dependent, UTF-16 or UTF-32. Makes a copy.
|
||||
std::string toAscii() const; // Returns only values 0-127, 7-bit ASCII. Makes a copy.
|
||||
|
||||
inline bool isUtf8() const { return m_Iterator == utf8Iterator; }
|
||||
inline bool isUtf16() const { return m_Iterator == utf16Iterator; }
|
||||
inline bool isUtf32() const { return m_Iterator == utf32Iterator; }
|
||||
|
||||
struct const_iterator
|
||||
{
|
||||
public:
|
||||
inline void operator++()
|
||||
{
|
||||
if ((ptrdiff_t)m_Next > ((ptrdiff_t)m_View.m_Str + m_View.m_Size))
|
||||
m_Next = (void *)((ptrdiff_t)m_View.m_Str + m_View.m_Size);
|
||||
m_Addr = m_Next;
|
||||
m_Char = m_View.m_Iterator(&m_Next);
|
||||
}
|
||||
inline void operator+=(ptrdiff_t a)
|
||||
{
|
||||
while ((ptrdiff_t)m_Addr < ((ptrdiff_t)m_View.m_Str + m_View.m_Size))
|
||||
{
|
||||
++(*this);
|
||||
}
|
||||
}
|
||||
inline bool operator!=(const const_iterator &o) const { return m_Addr != o.m_Addr; }
|
||||
inline bool operator==(const const_iterator &o) const { return m_Addr == o.m_Addr; }
|
||||
inline const u32char &operator*() const { return m_Char; }
|
||||
const_iterator() : m_View(*(CUtfStringView *)NULL), m_Addr(NULL), m_Char(0) { }
|
||||
|
||||
const_iterator &operator=(const const_iterator &other)
|
||||
{
|
||||
if (this == &other) return *this;
|
||||
this->~const_iterator();
|
||||
return *new(this) const_iterator(other);
|
||||
}
|
||||
|
||||
const void *ptr() const { return m_Addr; }
|
||||
private:
|
||||
friend class CUtfStringView;
|
||||
inline const_iterator(const CUtfStringView &view, const void *addr) : m_View(view), m_Addr(addr), m_Next(addr), m_Char(view.m_Iterator(&m_Next))
|
||||
{
|
||||
if ((ptrdiff_t)m_Next > ((ptrdiff_t)m_View.m_Str + m_View.m_Size))
|
||||
m_Next = (void *)((ptrdiff_t)m_View.m_Str + m_View.m_Size);
|
||||
}
|
||||
inline const_iterator(const CUtfStringView &view) : m_View(view), m_Addr((char *)view.m_Str + view.m_Size), m_Next((char *)view.m_Str + view.m_Size + 1), m_Char(0) { }
|
||||
const CUtfStringView &m_View;
|
||||
const void *m_Addr; // Current address
|
||||
const void *m_Next; // Next address
|
||||
u32char m_Char;
|
||||
};
|
||||
|
||||
typedef const_iterator iterator;
|
||||
|
||||
iterator begin() const { return iterator(*this, m_Str); }
|
||||
inline iterator end() const { return iterator(*this); }
|
||||
|
||||
/// Largest possible number of characters in this string.
|
||||
/// Number of actual characters may be less or equal.
|
||||
inline size_t largestSize() const { return m_Size; }
|
||||
|
||||
inline bool empty() const { return !m_Size; }
|
||||
const void *ptr() const { return m_Str; }
|
||||
|
||||
size_t count() const; //< Slow count of UTF-32 codepoints
|
||||
ptrdiff_t offset(ptrdiff_t i); const //< Get byte offset by utf-32 codepoint index
|
||||
|
||||
inline CUtfStringView substr(const iterator &begin, const iterator &end) const
|
||||
{
|
||||
return CUtfStringView(begin.m_Addr, (ptrdiff_t)end.m_Addr - (ptrdiff_t)begin.m_Addr, m_Iterator);
|
||||
}
|
||||
|
||||
inline bool endsWith(char c) { nlassert(c < 0x80); return *((char *)m_Str + m_Size - 1) == c; }
|
||||
|
||||
CUtfStringView &operator=(const CUtfStringView &other)
|
||||
{
|
||||
if(this == &other) return *this;
|
||||
this->~CUtfStringView();
|
||||
return *new(this) CUtfStringView(other);
|
||||
}
|
||||
|
||||
static void append(std::string &str, u32char c);
|
||||
|
||||
/// Encode or decode a single UTF-8 character in a stream (also useful for packing unsigned 20-bit integers)
|
||||
static void append(IStream &s, u32char c);
|
||||
static u32char get(IStream &s);
|
||||
|
||||
/// Get an UTF-8 string from an undefined ASCII-based codepage, without attempting to convert non-7-bit characters
|
||||
static std::string fromAscii(const std::string &str);
|
||||
|
||||
private:
|
||||
typedef u32char (*TIterator)(const void **addr);
|
||||
static u32char utf8Iterator(const void **addr);
|
||||
static u32char utf16Iterator(const void **addr);
|
||||
static u32char utf32Iterator(const void **addr);
|
||||
|
||||
inline CUtfStringView(const void *str, size_t len, TIterator it) : m_Str(str), m_Size(len), m_Iterator(it) { }
|
||||
|
||||
const void *const m_Str; // String
|
||||
const size_t m_Size; // Size in bytes
|
||||
const TIterator m_Iterator;
|
||||
|
||||
}; /* class CUtfStringView */
|
||||
|
||||
} /* namespace NLMISC */
|
||||
|
||||
#endif /* #ifndef NLMISC_UTF_STRING_VIEW_H */
|
||||
|
||||
/* end of file */
|
@ -1,74 +0,0 @@
|
||||
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
|
||||
// Copyright (C) 2010 Winch Gate Property Limited
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
|
||||
#ifndef XML_MACROS_H
|
||||
#define XML_MACROS_H
|
||||
|
||||
//
|
||||
// xmlNodePtr cur;
|
||||
// CXMLAutoPtr prop;
|
||||
//
|
||||
// sint i;
|
||||
// XML_READ_SINT(cur, "prop_name", i, -1);
|
||||
//
|
||||
|
||||
#define XML_READ_UINT(node, name, var, def) { \
|
||||
uint tmp; \
|
||||
prop = (char *) xmlGetProp(node, (xmlChar*)name); \
|
||||
if (prop && fromString((const char*)prop, tmp)) \
|
||||
var = tmp; \
|
||||
else \
|
||||
var = def; \
|
||||
}
|
||||
|
||||
#define XML_READ_SINT(node, name, var, def) { \
|
||||
sint tmp; \
|
||||
prop = (char *) xmlGetProp(node, (xmlChar*)name); \
|
||||
if (prop && fromString((const char*)prop, tmp)) \
|
||||
var = tmp; \
|
||||
else \
|
||||
var = def; \
|
||||
}
|
||||
|
||||
#define XML_READ_BOOL(node, name, var, def) { \
|
||||
prop = (char *) xmlGetProp(node, (xmlChar*)name); \
|
||||
if (prop) \
|
||||
var = NLMISC::toBool((const char*)prop); \
|
||||
else \
|
||||
var = def; \
|
||||
}
|
||||
|
||||
#define XML_READ_COLOR(node, name, var, def) { \
|
||||
NLMISC::CRGBA tmp; \
|
||||
prop = (char *) xmlGetProp(node, (xmlChar*)name); \
|
||||
if (prop && fromString((const char*)prop, tmp)) \
|
||||
var = tmp; \
|
||||
else \
|
||||
var = def; \
|
||||
}
|
||||
|
||||
#define XML_READ_STRING(node, name, var, def) { \
|
||||
prop = (char *) xmlGetProp(node, (xmlChar*)name); \
|
||||
if (prop) \
|
||||
var = (const char*)prop; \
|
||||
else \
|
||||
var = def; \
|
||||
}
|
||||
|
||||
#endif // XML_MACROS_H
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue