diff options
author | Kent Quirk <q@lindenlab.com> | 2009-01-05 18:59:12 +0000 |
---|---|---|
committer | Kent Quirk <q@lindenlab.com> | 2009-01-05 18:59:12 +0000 |
commit | 667ca55bad0108c4bdf8f007b89e1a52fc766aad (patch) | |
tree | 7bd62ac8d9af079c3994565f3f200ccc250bbc28 /indra/llcommon | |
parent | 95f365789f4cebc7bd97ccefd538f14d481a8373 (diff) |
svn merge -r106715:HEAD svn+ssh://svn.lindenlab.com/svn/linden/branches/q/notifications-merge-r106715 . QAR-1149 -- Final merge of notifications to trunk.
Diffstat (limited to 'indra/llcommon')
-rw-r--r-- | indra/llcommon/lldate.cpp | 17 | ||||
-rw-r--r-- | indra/llcommon/lldate.h | 29 | ||||
-rw-r--r-- | indra/llcommon/llmemory.h | 59 | ||||
-rw-r--r-- | indra/llcommon/llsd.cpp | 40 | ||||
-rw-r--r-- | indra/llcommon/llsd.h | 4 | ||||
-rw-r--r-- | indra/llcommon/lltimer.cpp | 8 | ||||
-rw-r--r-- | indra/llcommon/lltimer.h | 2 | ||||
-rw-r--r-- | indra/llcommon/lluuid.cpp | 15 | ||||
-rw-r--r-- | indra/llcommon/lluuid.h | 5 |
9 files changed, 138 insertions, 41 deletions
diff --git a/indra/llcommon/lldate.cpp b/indra/llcommon/lldate.cpp index 6b4bd0d7ef..ff1b6c5334 100644 --- a/indra/llcommon/lldate.cpp +++ b/indra/llcommon/lldate.cpp @@ -36,9 +36,12 @@ #include "apr_time.h" +#include <time.h> #include <iomanip> #include <sstream> +#include "lltimer.h" + static const F64 DATE_EPOCH = 0.0; static const F64 LL_APR_USEC_PER_SEC = 1000000.0; @@ -122,7 +125,7 @@ void LLDate::toHTTPDateStream(std::ostream& s) const << " GMT"; // RFC 1123 date does not use microseconds - llinfos << "Date in RFC 1123 format is " << s << llendl; + //llinfos << "Date in RFC 1123 format is " << s << llendl; } void LLDate::toStream(std::ostream& s) const @@ -239,6 +242,17 @@ bool operator!=(const LLDate& first, const LLDate& second) return (first.secondsSinceEpoch() != second.secondsSinceEpoch()); } +/* static */ LLDate LLDate::now() +{ + // time() returns seconds, we want fractions of a second, which LLTimer provides --RN + return LLDate(LLTimer::getTotalSeconds()); +} + +bool LLDate::operator<(const LLDate& rhs) const +{ + return mSecondsSinceEpoch < rhs.mSecondsSinceEpoch; +} + std::ostream& operator<<(std::ostream& s, const LLDate& date) { date.toStream(s); @@ -250,3 +264,4 @@ std::istream& operator>>(std::istream& s, LLDate& date) date.fromStream(s); return s; } + diff --git a/indra/llcommon/lldate.h b/indra/llcommon/lldate.h index 2b53c8cc9a..b660f9fcdd 100644 --- a/indra/llcommon/lldate.h +++ b/indra/llcommon/lldate.h @@ -35,6 +35,7 @@ #define LL_LLDATE_H #include <iosfwd> +#include <string> #include "stdtypes.h" @@ -53,7 +54,7 @@ public: LLDate(); /** - * @brief Construct a date equal to epoch. + * @brief Construct a date equal the source date. */ LLDate(const LLDate& date); @@ -111,6 +112,32 @@ public: * @param seconds The number of seconds since epoch UTC. */ void secondsSinceEpoch(F64 seconds); + + /** + * @brief Create an LLDate object set to the current time. + * + * @return The number of seconds since epoch UTC. + */ + static LLDate now(); + + /** + * @brief Compare dates using operator< so we can order them using STL. + * + * @param rhs -- the right hand side of the comparison operator + */ + bool operator<(const LLDate& rhs) const; + + /** + * @brief Remaining comparison operators in terms of operator< + * This conforms to the expectation of STL. + * + * @param rhs -- the right hand side of the comparison operator + */ + bool operator>(const LLDate& rhs) const { return rhs < *this; } + bool operator<=(const LLDate& rhs) const { return !(rhs < *this); } + bool operator>=(const LLDate& rhs) const { return !(*this < rhs); } + bool operator!=(const LLDate& rhs) const { return (*this < rhs) || (rhs < *this); } + bool operator==(const LLDate& rhs) const { return !(*this != rhs); } private: F64 mSecondsSinceEpoch; diff --git a/indra/llcommon/llmemory.h b/indra/llcommon/llmemory.h index cc57e658fb..3f3dd33ee3 100644 --- a/indra/llcommon/llmemory.h +++ b/indra/llcommon/llmemory.h @@ -409,53 +409,58 @@ protected: // // class Foo: public LLSingleton<Foo>{}; // -// Foo* instance = Foo::getInstance(); +// Foo& instance = Foo::instance(); // -// The second way is to define a seperate class that exposes the singleton -// interface: +// The second way is to use the singleton class directly, without inheritance: // -// class FooSingleton: public LLSingleton<Foo>{}; +// typedef LLSingleton<Foo> FooSingleton; // -// Foo* instance = FooSingleton::getInstance(); +// Foo& instance = FooSingleton::instance(); +// +// In this case, the class being managed as a singleton needs to provide an +// initSingleton() method since the LLSingleton virtual method won't be +// available // // As currently written, it is not thread-safe. -#if LL_WINDOWS && _MSC_VER < 1400 // this is Visual C++ 2003 or earlier -// workaround for VC7 compiler bug -// adapted from http://www.codeproject.com/KB/tips/VC2003MeyersSingletonBug.aspx -// our version doesn't introduce a nested struct so that you can still declare LLSingleton<MyClass> -// a friend and hide your constructor - template <typename T> class LLSingleton { public: - static T* getInstance() + virtual ~LLSingleton() {} +#ifdef LL_MSVC7 +// workaround for VC7 compiler bug +// adapted from http://www.codeproject.com/KB/tips/VC2003MeyersSingletonBug.aspx +// our version doesn't introduce a nested struct so that you can still declare LLSingleton<MyClass> +// a friend and hide your constructor + static T* getInstance() { LLSingleton<T> singleton; - return singleton.get(); - } -private: - T* get() - { - static T instance; - return &instance; + return singleton.vsHack(); } -}; + T* vsHack() #else - -template <typename T> -class LLSingleton -{ -public: static T* getInstance() +#endif { static T instance; + static bool needs_init = true; + if (needs_init) + { + needs_init = false; + instance.initSingleton(); + } return &instance; } -}; -#endif + static T& instance() + { + return *getInstance(); + } + +private: + virtual void initSingleton() {} +}; //---------------------------------------------------------------------------- diff --git a/indra/llcommon/llsd.cpp b/indra/llcommon/llsd.cpp index 099f233f56..4bf4e442fd 100644 --- a/indra/llcommon/llsd.cpp +++ b/indra/llcommon/llsd.cpp @@ -349,7 +349,7 @@ namespace virtual bool has(const LLSD::String&) const; virtual LLSD get(const LLSD::String&) const; - void insert(const LLSD::String& k, const LLSD& v); + LLSD& insert(const LLSD::String& k, const LLSD& v); virtual void erase(const LLSD::String&); LLSD& ref(const LLSD::String&); virtual const LLSD& ref(const LLSD::String&) const; @@ -388,9 +388,14 @@ namespace return (i != mData.end()) ? i->second : LLSD(); } - void ImplMap::insert(const LLSD::String& k, const LLSD& v) + LLSD& ImplMap::insert(const LLSD::String& k, const LLSD& v) { mData.insert(DataMap::value_type(k, v)); + #ifdef LL_MSVC7 + return *((LLSD*)this); + #else + return *dynamic_cast<LLSD*>(this); + #endif } void ImplMap::erase(const LLSD::String& k) @@ -436,7 +441,7 @@ namespace virtual int size() const; virtual LLSD get(LLSD::Integer) const; void set(LLSD::Integer, const LLSD&); - void insert(LLSD::Integer, const LLSD&); + LLSD& insert(LLSD::Integer, const LLSD&); void append(const LLSD&); virtual void erase(LLSD::Integer); LLSD& ref(LLSD::Integer); @@ -485,9 +490,15 @@ namespace mData[index] = v; } - void ImplArray::insert(LLSD::Integer i, const LLSD& v) + LLSD& ImplArray::insert(LLSD::Integer i, const LLSD& v) { - if (i < 0) { return; } + if (i < 0) { + #ifdef LL_MSVC7 + return *((LLSD*)this); + #else + return *dynamic_cast<LLSD*>(this); + #endif + } DataVector::size_type index = i; if (index >= mData.size()) @@ -496,6 +507,11 @@ namespace } mData.insert(mData.begin() + index, v); + #ifdef LL_MSVC7 + return *((LLSD*)this); + #else + return *dynamic_cast<LLSD*>(this); + #endif } void ImplArray::append(const LLSD& v) @@ -739,8 +755,11 @@ LLSD LLSD::emptyMap() bool LLSD::has(const String& k) const { return safe(impl).has(k); } LLSD LLSD::get(const String& k) const { return safe(impl).get(k); } -void LLSD::insert(const String& k, const LLSD& v) - { makeMap(impl).insert(k, v); } +LLSD& LLSD::insert(const String& k, const LLSD& v) + { + makeMap(impl).insert(k, v); + return *dynamic_cast<LLSD*>(this); + } void LLSD::erase(const String& k) { makeMap(impl).erase(k); } LLSD& LLSD::operator[](const String& k) @@ -761,8 +780,11 @@ int LLSD::size() const { return safe(impl).size(); } LLSD LLSD::get(Integer i) const { return safe(impl).get(i); } void LLSD::set(Integer i, const LLSD& v){ makeArray(impl).set(i, v); } -void LLSD::insert(Integer i, const LLSD& v) - { makeArray(impl).insert(i, v); } +LLSD& LLSD::insert(Integer i, const LLSD& v) + { + makeArray(impl).insert(i, v); + return *this; + } void LLSD::append(const LLSD& v) { makeArray(impl).append(v); } void LLSD::erase(Integer i) { makeArray(impl).erase(i); } diff --git a/indra/llcommon/llsd.h b/indra/llcommon/llsd.h index 0382fb1360..87874009dd 100644 --- a/indra/llcommon/llsd.h +++ b/indra/llcommon/llsd.h @@ -222,7 +222,7 @@ public: bool has(const String&) const; LLSD get(const String&) const; - void insert(const String&, const LLSD&); + LLSD& insert(const String&, const LLSD&); void erase(const String&); LLSD& operator[](const String&); @@ -237,7 +237,7 @@ public: LLSD get(Integer) const; void set(Integer, const LLSD&); - void insert(Integer, const LLSD&); + LLSD& insert(Integer, const LLSD&); void append(const LLSD&); void erase(Integer); diff --git a/indra/llcommon/lltimer.cpp b/indra/llcommon/lltimer.cpp index 2c34608064..2525e24989 100644 --- a/indra/llcommon/lltimer.cpp +++ b/indra/llcommon/lltimer.cpp @@ -569,6 +569,14 @@ LLEventTimer::LLEventTimer(F32 period) sActiveList.push_back(this); } +LLEventTimer::LLEventTimer(const LLDate& time) +: mEventTimer() +{ + mPeriod = (F32)(time.secondsSinceEpoch() - LLDate::now().secondsSinceEpoch()); + sActiveList.push_back(this); +} + + LLEventTimer::~LLEventTimer() { sActiveList.remove(this); diff --git a/indra/llcommon/lltimer.h b/indra/llcommon/lltimer.h index 1916d67fda..6d6f1f44cd 100644 --- a/indra/llcommon/lltimer.h +++ b/indra/llcommon/lltimer.h @@ -38,6 +38,7 @@ #include <limits.h> #include "stdtypes.h" +#include "lldate.h" #include <string> #include <list> @@ -173,6 +174,7 @@ class LLEventTimer { public: LLEventTimer(F32 period); // period is the amount of time between each call to tick() in seconds + LLEventTimer(const LLDate& time); virtual ~LLEventTimer(); //function to be called at the supplied frequency diff --git a/indra/llcommon/lluuid.cpp b/indra/llcommon/lluuid.cpp index 1098d1bd3c..019c5045d4 100644 --- a/indra/llcommon/lluuid.cpp +++ b/indra/llcommon/lluuid.cpp @@ -908,6 +908,21 @@ BOOL LLUUID::parseUUID(const std::string& buf, LLUUID* value) return FALSE; } +//static +LLUUID LLUUID::generateNewID(std::string hash_string) +{ + LLUUID new_id; + if (hash_string.empty()) + { + new_id.generate(); + } + else + { + new_id.generate(hash_string); + } + return new_id; +} + LLAssetID LLTransactionID::makeAssetID(const LLUUID& session) const { LLAssetID result; diff --git a/indra/llcommon/lluuid.h b/indra/llcommon/lluuid.h index b2fcce5161..e5c204b589 100644 --- a/indra/llcommon/lluuid.h +++ b/indra/llcommon/lluuid.h @@ -65,6 +65,9 @@ public: // void generate(); // Generate a new UUID void generate(const std::string& stream); //Generate a new UUID based on hash of input stream + + static LLUUID generateNewID(std::string stream = ""); //static version of above for use in initializer expressions such as constructor params, etc. + BOOL set(const char *in_string, BOOL emit = TRUE); // Convert from string, if emit is FALSE, do not emit warnings BOOL set(const std::string& in_string, BOOL emit = TRUE); // Convert from string, if emit is FALSE, do not emit warnings void setNull(); // Faster than setting to LLUUID::null. @@ -124,7 +127,7 @@ public: static S32 getNodeID(unsigned char * node_id); static BOOL parseUUID(const std::string& buf, LLUUID* value); - + U8 mData[UUID_BYTES]; }; |