Browse Source

tags/2021-05-28
jules 18 years ago
parent
commit
6acfb2c125
7 changed files with 133 additions and 1 deletions
  1. +48
    -0
      src/juce_core/containers/juce_PropertySet.cpp
  2. +20
    -0
      src/juce_core/containers/juce_PropertySet.h
  3. +14
    -0
      src/juce_core/io/juce_InputStream.cpp
  4. +20
    -0
      src/juce_core/io/juce_InputStream.h
  5. +14
    -0
      src/juce_core/io/juce_OutputStream.cpp
  6. +16
    -0
      src/juce_core/io/juce_OutputStream.h
  7. +1
    -1
      src/juce_core/io/network/juce_Socket.cpp

+ 48
- 0
src/juce_core/containers/juce_PropertySet.cpp View File

@@ -68,6 +68,17 @@ PropertySet::~PropertySet()
{
}
void PropertySet::clear()
{
const ScopedLock sl (lock);
if (properties.size() > 0)
{
properties.clear();
propertyChanged();
}
}
const String PropertySet::getValue (const String& keyName,
const String& defaultValue) const throw()
{
@@ -200,6 +211,43 @@ void PropertySet::setFallbackPropertySet (PropertySet* fallbackProperties_) thro
fallbackProperties = fallbackProperties_;
}
XmlElement* PropertySet::createXml (const String& nodeName) const throw()
{
const ScopedLock sl (lock);
XmlElement* const xml = new XmlElement (nodeName);
for (int i = 0; i < properties.getAllKeys().size(); ++i)
{
XmlElement* const e = new XmlElement (T("VALUE"));
e->setAttribute (T("name"), properties.getAllKeys()[i]);
e->setAttribute (T("val"), properties.getAllValues()[i]);
xml->addChildElement (e);
}
return xml;
}
void PropertySet::restoreFromXml (const XmlElement& xml) throw()
{
const ScopedLock sl (lock);
clear();
forEachXmlChildElementWithTagName (xml, e, T("VALUE"))
{
if (e->hasAttribute (T("name"))
&& e->hasAttribute (T("val")))
{
properties.set (e->getStringAttribute (T("name")),
e->getStringAttribute (T("val")));
}
}
if (properties.size() > 0)
propertyChanged();
}
void PropertySet::propertyChanged()
{
}


+ 20
- 0
src/juce_core/containers/juce_PropertySet.h View File

@@ -188,6 +188,9 @@ public:
/** Returns true if the properies include the given key. */
bool containsKey (const String& keyName) const throw();
/** Removes all values. */
void clear();
//==============================================================================
/** Returns the keys/value pair array containing all the properties. */
StringPairArray& getAllProperties() throw() { return properties; }
@@ -195,6 +198,23 @@ public:
/** Returns the lock used when reading or writing to this set */
const CriticalSection& getLock() const throw() { return lock; }
//==============================================================================
/** Returns an XML element which encapsulates all the items in this property set.
The string parameter is the tag name that should be used for the node.
@see restoreFromXml
*/
XmlElement* createXml (const String& nodeName) const throw();
/** Reloads a set of properties that were previously stored as XML.
The node passed in must have been created by the createXml() method.
@see createXml
*/
void restoreFromXml (const XmlElement& xml) throw();
//==============================================================================
/** Sets up a second PopertySet that will be used to look up any values that aren't
set in this one.


+ 14
- 0
src/juce_core/io/juce_InputStream.cpp View File

@@ -140,6 +140,13 @@ float InputStream::readFloat()
return n.asFloat;
}
float InputStream::readFloatBigEndian()
{
union { int asInt; float asFloat; } n;
n.asInt = readIntBigEndian();
return n.asFloat;
}
double InputStream::readDouble()
{
union { int64 asInt; double asDouble; } n;
@@ -147,6 +154,13 @@ double InputStream::readDouble()
return n.asDouble;
}
double InputStream::readDoubleBigEndian()
{
union { int64 asInt; double asDouble; } n;
n.asInt = readInt64BigEndian();
return n.asDouble;
}
const String InputStream::readString()
{
const int tempBufferSize = 256;


+ 20
- 0
src/juce_core/io/juce_InputStream.h View File

@@ -176,6 +176,16 @@ public:
*/
virtual float readFloat();
/** Reads four bytes as a 32-bit floating point value.
The raw 32-bit encoding of the float is read from the stream as a big-endian int.
If the stream is exhausted partway through reading the bytes, this will return zero.
@see OutputStream::writeFloatBigEndian, readDoubleBigEndian
*/
virtual float readFloatBigEndian();
/** Reads eight bytes as a 64-bit floating point value.
The raw 64-bit encoding of the double is read from the stream as a little-endian int64.
@@ -186,6 +196,16 @@ public:
*/
virtual double readDouble();
/** Reads eight bytes as a 64-bit floating point value.
The raw 64-bit encoding of the double is read from the stream as a big-endian int64.
If the stream is exhausted partway through reading the bytes, this will return zero.
@see OutputStream::writeDoubleBigEndian, readFloatBigEndian
*/
virtual double readDoubleBigEndian();
/** Reads an encoded 32-bit number from the stream using a space-saving compressed format.
For small values, this is more space-efficient than using readInt() and OutputStream::writeInt()


+ 14
- 0
src/juce_core/io/juce_OutputStream.cpp View File

@@ -114,6 +114,13 @@ void OutputStream::writeFloat (float value)
writeInt (n.asInt);
}
void OutputStream::writeFloatBigEndian (float value)
{
union { int asInt; float asFloat; } n;
n.asFloat = value;
writeIntBigEndian (n.asInt);
}
void OutputStream::writeDouble (double value)
{
union { int64 asInt; double asDouble; } n;
@@ -121,6 +128,13 @@ void OutputStream::writeDouble (double value)
writeInt64 (n.asInt);
}
void OutputStream::writeDoubleBigEndian (double value)
{
union { int64 asInt; double asDouble; } n;
n.asDouble = value;
writeInt64BigEndian (n.asInt);
}
void OutputStream::writeString (const String& text)
{
const int numBytes = text.copyToUTF8 (0);


+ 16
- 0
src/juce_core/io/juce_OutputStream.h View File

@@ -150,6 +150,14 @@ public:
*/
virtual void writeFloat (float value);
/** Writes a 32-bit floating point value to the stream.
The binary 32-bit encoding of the float is written as a big-endian int.
@see InputStream::readFloatBigEndian
*/
virtual void writeFloatBigEndian (float value);
/** Writes a 64-bit floating point value to the stream.
The eight raw bytes of the double value are written out as a little-endian 64-bit int.
@@ -158,6 +166,14 @@ public:
*/
virtual void writeDouble (double value);
/** Writes a 64-bit floating point value to the stream.
The eight raw bytes of the double value are written out as a big-endian 64-bit int.
@see InputStream::readDoubleBigEndian
*/
virtual void writeDoubleBigEndian (double value);
/** Writes a condensed encoding of a 32-bit integer.
If you're storing a lot of integers which are unlikely to have very large values,


+ 1
- 1
src/juce_core/io/network/juce_Socket.cpp View File

@@ -243,7 +243,7 @@ static bool connectSocket (int volatile& handle,
servTmpAddr.sin_addr = targetAddress;
servTmpAddr.sin_port = htons ((uint16) portNumber);
if (handle < 0)
if (handle < 0)
handle = (int) socket (AF_INET, isDatagram ? SOCK_DGRAM : SOCK_STREAM, 0);
if (handle < 0)


Loading…
Cancel
Save