Misc llcommon tidbits from v2.

This commit is contained in:
Shyotl
2011-03-15 02:28:22 -05:00
parent 343bb22b5c
commit 62d7f3d59f
9 changed files with 68 additions and 25 deletions

View File

@@ -246,9 +246,9 @@ public:
return rtn;
}
LLVisualParam* getVisualParam(S32 id)
LLVisualParam* getVisualParam(S32 id) const
{
visual_param_index_map_t::iterator iter = mVisualParamIndexMap.find(id);
visual_param_index_map_t::const_iterator iter = mVisualParamIndexMap.find(id);
return (iter == mVisualParamIndexMap.end()) ? 0 : iter->second;
}
S32 getVisualParamID(LLVisualParam *id)

View File

@@ -202,7 +202,7 @@ public:
{
U32 n = mVector.size();
mIndexMap[k] = n;
mVector.resize(n+1);
mVector.push_back(Type());
llassert(mVector.size() == mIndexMap.size());
return mVector[n];
}

View File

@@ -75,6 +75,10 @@ const int LL_ERR_PRICE_MISMATCH = -23018;
#define SHOW_ASSERT
#else // _DEBUG
#ifdef LL_RELEASE_WITH_DEBUG_INFO
#define SHOW_ASSERT
#endif // LL_RELEASE_WITH_DEBUG_INFO
#ifdef RELEASE_SHOW_DEBUG
#define SHOW_DEBUG
#endif
@@ -103,17 +107,14 @@ const int LL_ERR_PRICE_MISMATCH = -23018;
#define llwarning(msg, num) llwarns << "Warning # " << num << ": " << msg << llendl;
#ifdef SHOW_ASSERT
#define llassert(func) if (!(func)) llerrs << "ASSERT (" << #func << ")" << llendl;
#else
#define llassert(func)
#endif
#define llassert_always(func) if (!(func)) llerrs << "ASSERT (" << #func << ")" << llendl;
#define llassert_always(func) if (LL_UNLIKELY(!(func))) llerrs << "ASSERT (" << #func << ")" << llendl;
#ifdef SHOW_ASSERT
#define llverify(func) if (!(func)) llerrs << "ASSERT (" << #func << ")" << llendl;
#define llassert(func) llassert_always(func)
#define llverify(func) llassert_always(func)
#else
#define llverify(func) (func); // get rid of warning C4189
#define llassert(func)
#define llverify(func) do {if (func) {}} while(0)
#endif
// handy compile-time assert - enforce those template parameters!

View File

@@ -98,6 +98,17 @@ LLFILE* LLFile::_fsopen(const std::string& filename, const char* mode, int shari
#endif
}
int LLFile::close(LLFILE * file)
{
int ret_value = 0;
if (file)
{
ret_value = fclose(file);
}
return ret_value;
}
int LLFile::remove(const std::string& filename)
{
#if LL_WINDOWS

View File

@@ -77,6 +77,8 @@ public:
static LLFILE* fopen(const std::string& filename,const char* accessmode); /* Flawfinder: ignore */
static LLFILE* _fsopen(const std::string& filename,const char* accessmode,int sharingFlag);
static int close(LLFILE * file);
// perms is a permissions mask like 0777 or 0700. In most cases it will
// be overridden by the user's umask. It is ignored on Windows.
static int mkdir(const std::string& filename, int perms = 0700);

View File

@@ -192,9 +192,10 @@ void LLMD5::update(std::istream& stream){
}
void LLMD5::update(const std::string& s)
{
update((unsigned char *)s.c_str(),s.length());
}
// MD5 finalization. Ends an MD5 message-digest operation, writing the
// the message digest and zeroizing the context.
@@ -277,7 +278,7 @@ LLMD5::LLMD5(const unsigned char *s)
finalize();
}
void LLMD5::raw_digest(unsigned char *s)
void LLMD5::raw_digest(unsigned char *s) const
{
if (!finalized)
{
@@ -293,7 +294,7 @@ void LLMD5::raw_digest(unsigned char *s)
void LLMD5::hex_digest(char *s)
void LLMD5::hex_digest(char *s) const
{
int i;
@@ -327,13 +328,25 @@ std::ostream& operator<<(std::ostream &stream, LLMD5 context)
return stream;
}
bool operator==(const LLMD5& a, const LLMD5& b)
{
unsigned char a_guts[16];
unsigned char b_guts[16];
a.raw_digest(a_guts);
b.raw_digest(b_guts);
if (memcmp(a_guts,b_guts,16)==0)
return true;
else
return false;
}
bool operator!=(const LLMD5& a, const LLMD5& b)
{
return !(a==b);
}
// PRIVATE METHODS:
void LLMD5::init(){
finalized=0; // we just started!

View File

@@ -95,6 +95,7 @@ public:
void update (const uint1 *input, const uint4 input_length);
void update (std::istream& stream);
void update (FILE *file);
void update (const std::string& str);
void finalize ();
// constructors for special circumstances. All these constructors finalize
@@ -105,8 +106,8 @@ public:
LLMD5 (const unsigned char *string, const unsigned int number);
// methods to acquire finalized result
void raw_digest(unsigned char *array); // provide 16-byte array for binary data
void hex_digest(char *string); // provide 33-byte array for ascii-hex string
void raw_digest(unsigned char *array) const; // provide 16-byte array for binary data
void hex_digest(char *string) const; // provide 33-byte array for ascii-hex string
friend std::ostream& operator<< (std::ostream&, LLMD5 context);
@@ -131,4 +132,7 @@ private:
};
LL_COMMON_API bool operator==(const LLMD5& a, const LLMD5& b);
LL_COMMON_API bool operator!=(const LLMD5& a, const LLMD5& b);
#endif // LL_LLMD5_H

View File

@@ -77,7 +77,7 @@ void LLSDSerialize::serialize(const LLSD& sd, std::ostream& str, ELLSD_Serialize
break;
default:
llwarns << "serialize request for unkown ELLSD_Serialize" << llendl;
llwarns << "serialize request for unknown ELLSD_Serialize" << llendl;
}
if (f.notNull())

View File

@@ -46,10 +46,21 @@
void encode_character(std::ostream& ostr, std::string::value_type val)
{
ostr << "%" << std::uppercase << std::hex << std::setw(2) << std::setfill('0')
ostr << "%"
<< std::uppercase
<< std::hex
<< std::setw(2)
<< std::setfill('0')
// VWR-4010 Cannot cast to U32 because sign-extension on
// chars > 128 will result in FFFFFFC3 instead of F3.
<< static_cast<S32>(static_cast<U8>(val));
<< static_cast<S32>(static_cast<U8>(val))
// reset stream state
<< std::nouppercase
<< std::dec
<< std::setfill(' ');
}
// static
@@ -221,7 +232,8 @@ static BOOL isDefault(const std::string& scheme, U16 port)
void LLURI::parseAuthorityAndPathUsingOpaque()
{
if (mScheme == "http" || mScheme == "https" ||
mScheme == "ftp" || mScheme == "secondlife" )
mScheme == "ftp" || mScheme == "secondlife" ||
mScheme == "x-grid-location-info")
{
if (mEscapedOpaque.substr(0,2) != "//")
{