Browse Source

Clarified comments around the JUCE_ALLOW_STATIC_NULL_VARIABLES items to make clear that they're deprecated

tags/2021-05-28
jules 7 years ago
parent
commit
85f74ca7d3
11 changed files with 58 additions and 76 deletions
  1. +0
    -4
      modules/juce_core/containers/juce_NamedValueSet.cpp
  2. +12
    -5
      modules/juce_core/containers/juce_Variant.h
  3. +10
    -9
      modules/juce_core/files/juce_File.h
  4. +13
    -11
      modules/juce_core/text/juce_String.h
  5. +0
    -4
      modules/juce_core/text/juce_StringArray.cpp
  6. +0
    -4
      modules/juce_core/xml/juce_XmlElement.cpp
  7. +0
    -4
      modules/juce_data_structures/values/juce_ValueTree.cpp
  8. +6
    -7
      modules/juce_data_structures/values/juce_ValueTree.h
  9. +10
    -11
      modules/juce_graphics/geometry/juce_AffineTransform.h
  10. +7
    -8
      modules/juce_graphics/images/juce_Image.h
  11. +0
    -9
      modules/juce_gui_basics/juce_gui_basics.h

+ 0
- 4
modules/juce_core/containers/juce_NamedValueSet.cpp View File

@@ -120,12 +120,8 @@ bool NamedValueSet::isEmpty() const noexcept { return values.isEmpty(); }
static const var& getNullVarRef() noexcept
{
#if JUCE_ALLOW_STATIC_NULL_VARIABLES
return var::null;
#else
static var nullVar;
return nullVar;
#endif
}
const var& NamedValueSet::operator[] (const Identifier& name) const noexcept


+ 12
- 5
modules/juce_core/containers/juce_Variant.h View File

@@ -64,11 +64,6 @@ public:
/** Destructor. */
~var() noexcept;
#if JUCE_ALLOW_STATIC_NULL_VARIABLES
/** A static var object that can be used where you need an empty variant object. */
static const var null;
#endif
var (const var& valueToCopy);
var (int value) noexcept;
var (int64 value) noexcept;
@@ -277,6 +272,18 @@ public:
*/
static var readFromStream (InputStream& input);
#if JUCE_ALLOW_STATIC_NULL_VARIABLES
/** This was a static empty var object, but is now deprecated as it's too easy to accidentally
use it indirectly during a static constructor, leading to hard-to-find order-of-initialisation
problems.
@deprecated If you need a default-constructed var, just use var() or {}.
The only time you might miss having var::null available might be if you need to return an
empty var from a function by reference, but if you need to do that, it's easy enough to use
a function-local static var and return that, avoiding any order-of-initialisation issues.
*/
static const var null;
#endif
private:
//==============================================================================
class VariantType; friend class VariantType;


+ 10
- 9
modules/juce_core/files/juce_File.h View File

@@ -87,15 +87,6 @@ public:
/** Move assignment operator */
File& operator= (File&&) noexcept;
//==============================================================================
#if JUCE_ALLOW_STATIC_NULL_VARIABLES
/** This static constant is used for referring to an 'invalid' file.
Bear in mind that you should avoid this kind of static variable, and always prefer
to use File() or {} if you need a default-constructed File object.
*/
static const File nonexistent;
#endif
//==============================================================================
/** Checks whether the file actually exists.
@@ -1037,6 +1028,16 @@ public:
JUCE_DEPRECATED (static const StringRef separatorString);
#endif
//==============================================================================
#if JUCE_ALLOW_STATIC_NULL_VARIABLES
/** This was a static empty File object, but is now deprecated as it's too easy to accidentally
use it indirectly during a static constructor, leading to hard-to-find order-of-initialisation
problems.
@deprecated If you need a default-constructed File object, just use File() or {}.
*/
static const File nonexistent;
#endif
private:
//==============================================================================
String fullPath;


+ 13
- 11
modules/juce_core/text/juce_String.h View File

@@ -138,17 +138,6 @@ public:
/** Destructor. */
~String() noexcept;
//==============================================================================
#if JUCE_ALLOW_STATIC_NULL_VARIABLES
/** This is a static empty string object that can be used if you need a reference to one.
The value of String::empty is exactly the same as String(), and in almost all cases
it's better to avoid String::empty and just use String() or {} instead, so that the compiler
only has to reason about locally-constructed objects, rather than taking into account
the fact that you're referencing a global shared static memory address.
*/
static const String empty;
#endif
/** This is the character encoding type used internally to store the string.
By setting the value of JUCE_STRING_UTF_TYPE to 8, 16, or 32, you can change the
@@ -1247,6 +1236,19 @@ public:
*/
int getReferenceCount() const noexcept;
//==============================================================================
#if JUCE_ALLOW_STATIC_NULL_VARIABLES
/** This was a static empty string object, but is now deprecated as it's too easy to accidentally
use it indirectly during a static constructor, leading to hard-to-find order-of-initialisation
problems.
@deprecated If you need an empty String object, just use String() or {}.
The only time you might miss having String::empty available might be if you need to return an
empty string from a function by reference, but if you need to do that, it's easy enough to use
a function-local static String object and return that, avoiding any order-of-initialisation issues.
*/
static const String empty;
#endif
private:
//==============================================================================
CharPointerType text;


+ 0
- 4
modules/juce_core/text/juce_StringArray.cpp View File

@@ -120,12 +120,8 @@ const String& StringArray::operator[] (int index) const noexcept
if (isPositiveAndBelow (index, strings.size()))
return strings.getReference (index);
#if JUCE_ALLOW_STATIC_NULL_VARIABLES
return String::empty;
#else
static String empty;
return empty;
#endif
}
String& StringArray::getReference (int index) noexcept


+ 0
- 4
modules/juce_core/xml/juce_XmlElement.cpp View File

@@ -447,12 +447,8 @@ int XmlElement::getNumAttributes() const noexcept
static const String& getEmptyStringRef() noexcept
{
#if JUCE_ALLOW_STATIC_NULL_VARIABLES
return String::empty;
#else
static String empty;
return empty;
#endif
}
const String& XmlElement::getAttributeName (const int index) const noexcept


+ 0
- 4
modules/juce_data_structures/values/juce_ValueTree.cpp View File

@@ -688,12 +688,8 @@ ValueTree ValueTree::getSibling (int delta) const noexcept
static const var& getNullVarRef() noexcept
{
#if JUCE_ALLOW_STATIC_NULL_VARIABLES
return var::null;
#else
static var nullVar;
return nullVar;
#endif
}
const var& ValueTree::operator[] (const Identifier& name) const noexcept


+ 6
- 7
modules/juce_data_structures/values/juce_ValueTree.h View File

@@ -532,19 +532,18 @@ public:
}
}
/** Returns the total number of references to the shared underlying data structure that this
ValueTree is using.
*/
int getReferenceCount() const noexcept;
#if JUCE_ALLOW_STATIC_NULL_VARIABLES
/** An invalid ValueTree that can be used if you need to return one as an error condition, etc.
This invalid object is equivalent to ValueTree created with its default constructor, but
you should always prefer to avoid it and use ValueTree() or {} instead.
@deprecated If you need an empty ValueTree object, just use ValueTree() or {}.
*/
static const ValueTree invalid;
#endif
/** Returns the total number of references to the shared underlying data structure that this
ValueTree is using.
*/
int getReferenceCount() const noexcept;
private:
//==============================================================================
JUCE_PUBLIC_IN_DLL_BUILD (class SharedObject)


+ 10
- 11
modules/juce_graphics/geometry/juce_AffineTransform.h View File

@@ -68,20 +68,12 @@ public:
/** Compares two transforms. */
bool operator!= (const AffineTransform& other) const noexcept;
#if JUCE_ALLOW_STATIC_NULL_VARIABLES
/** A ready-to-use identity transform.
Note that you should always avoid using a static variable like this, and
prefer AffineTransform() or {} if you need a default-constructed instance.
*/
static const AffineTransform identity;
#endif
//==============================================================================
/** Transforms a 2D coordinate using this matrix. */
template <typename ValueType>
void transformPoint (ValueType& x, ValueType& y) const noexcept
{
const ValueType oldX = x;
auto oldX = x;
x = static_cast<ValueType> (mat00 * oldX + mat01 * y + mat02);
y = static_cast<ValueType> (mat10 * oldX + mat11 * y + mat12);
}
@@ -95,7 +87,7 @@ public:
void transformPoints (ValueType& x1, ValueType& y1,
ValueType& x2, ValueType& y2) const noexcept
{
const ValueType oldX1 = x1, oldX2 = x2;
auto oldX1 = x1, oldX2 = x2;
x1 = static_cast<ValueType> (mat00 * oldX1 + mat01 * y1 + mat02);
y1 = static_cast<ValueType> (mat10 * oldX1 + mat11 * y1 + mat12);
x2 = static_cast<ValueType> (mat00 * oldX2 + mat01 * y2 + mat02);
@@ -112,7 +104,7 @@ public:
ValueType& x2, ValueType& y2,
ValueType& x3, ValueType& y3) const noexcept
{
const ValueType oldX1 = x1, oldX2 = x2, oldX3 = x3;
auto oldX1 = x1, oldX2 = x2, oldX3 = x3;
x1 = static_cast<ValueType> (mat00 * oldX1 + mat01 * y1 + mat02);
y1 = static_cast<ValueType> (mat10 * oldX1 + mat11 * y1 + mat12);
x2 = static_cast<ValueType> (mat00 * oldX2 + mat01 * y2 + mat02);
@@ -276,6 +268,13 @@ public:
*/
float getScaleFactor() const noexcept;
#if JUCE_ALLOW_STATIC_NULL_VARIABLES
/** A ready-to-use identity transform - now depracated.
@deprecated If you need an identity transform, just use AffineTransform() or {}.
*/
static const AffineTransform identity;
#endif
//==============================================================================
/* The transform matrix is:


+ 7
- 8
modules/juce_graphics/images/juce_Image.h View File

@@ -153,14 +153,6 @@ public:
*/
inline bool isNull() const noexcept { return image == nullptr; }
#if JUCE_ALLOW_STATIC_NULL_VARIABLES
/** A null Image object that can be used when you need to return an invalid image.
This object is the equivalient to an Image created with the default constructor, and
you should always prefer to use Image() or {} when you need an empty image object.
*/
static const Image null;
#endif
//==============================================================================
/** Returns the image's width (in pixels). */
int getWidth() const noexcept;
@@ -420,6 +412,13 @@ public:
/** @internal */
explicit Image (ImagePixelData*) noexcept;
#if JUCE_ALLOW_STATIC_NULL_VARIABLES
/** A null Image object that can be used when you need to return an invalid image.
@deprecated If you need a default-constructed var, just use Image() or {}.
*/
static const Image null;
#endif
private:
//==============================================================================
ReferenceCountedObjectPtr<ImagePixelData> image;


+ 0
- 9
modules/juce_gui_basics/juce_gui_basics.h View File

@@ -117,8 +117,6 @@ namespace juce
class MouseInputSource;
class MouseInputSourceInternal;
class ComponentPeer;
class MarkerList;
class RelativeRectangle;
class MouseEvent;
struct MouseWheelDetails;
struct PenDetails;
@@ -130,28 +128,21 @@ namespace juce
class ComboBox;
class Button;
class FilenameComponent;
class DocumentWindow;
class ResizableWindow;
class GroupComponent;
class MenuBarComponent;
class DropShadower;
class GlyphArrangement;
class PropertyComponent;
class TableHeaderComponent;
class Toolbar;
class ToolbarItemComponent;
class PopupMenu;
class ProgressBar;
class FileBrowserComponent;
class DirectoryContentsDisplayComponent;
class FilePreviewComponent;
class ImageButton;
class CallOutBox;
class Drawable;
class DrawablePath;
class DrawableComposite;
class CaretComponent;
class BubbleComponent;
class KeyPressMappingSet;
class ApplicationCommandManagerListener;
class DrawableButton;


Loading…
Cancel
Save