Shuffled LL_COMMON_API around in spots to match v2

Added llformat_to_utf8
Added LLProcessLauncher::getExecutable()
LLStringTableEntry() ctor and dtor definitions moved from .h to .cpp
(should be safe)
This commit is contained in:
Shyotl
2011-05-15 22:47:23 -05:00
parent 51338470b5
commit fe372028dc
17 changed files with 107 additions and 49 deletions

View File

@@ -46,4 +46,18 @@
*/
typedef boost::tokenizer<boost::char_separator<char> > boost_tokenizer;
// Useful combiner for boost signals that return a bool (e.g. validation)
// returns false if any of the callbacks return false
struct boost_boolean_combiner
{
typedef bool result_type;
template<typename InputIterator>
bool operator()(InputIterator first, InputIterator last) const
{
bool res = true;
while (first != last)
res &= *first++;
return res;
}
};
#endif // LL_LLBOOST_H

View File

@@ -179,7 +179,7 @@ namespace LLError
{ return s; }
// used to indicate the end of a message
class NoClassInfo { };
class LL_COMMON_API NoClassInfo { };
// used to indicate no class info known for logging
//LLCallStacks keeps track of call stacks and output the call stacks to log file

View File

@@ -34,7 +34,7 @@
#ifndef LL_LLERRORLEGACY_H
#define LL_LLERRORLEGACY_H
#include "llpreprocessor.h"
/*
LEGACY -- DO NOT USE THIS STUFF ANYMORE

View File

@@ -233,7 +233,7 @@ public:
* and should only be used for config files and the like -- not in a
* loop.
*/
std::streamsize llifstream_size(llifstream& fstr);
std::streamsize llofstream_size(llofstream& fstr);
std::streamsize LL_COMMON_API llifstream_size(llifstream& fstr);
std::streamsize LL_COMMON_API llofstream_size(llofstream& fstr);
#endif // not LL_LLFILE_H

View File

@@ -37,17 +37,41 @@
#include <cstdarg>
std::string llformat(const char *fmt, ...)
// common used function with va_list argument
// wrapper for vsnprintf to be called from llformatXXX functions.
static void va_format(std::string& out, const char *fmt, va_list va)
{
char tstr[1024]; /* Flawfinder: ignore */
va_list va;
va_start(va, fmt);
#if LL_WINDOWS
_vsnprintf(tstr, 1024, fmt, va);
#else
vsnprintf(tstr, 1024, fmt, va); /* Flawfinder: ignore */
#endif
va_end(va);
tstr[1023] = '\0';
return std::string(tstr);
out.assign(tstr);
}
std::string llformat(const char *fmt, ...)
{
std::string res;
va_list va;
va_start(va, fmt);
va_format(res, fmt, va);
va_end(va);
return res;
}
std::string llformat_to_utf8(const char *fmt, ...)
{
std::string res;
va_list va;
va_start(va, fmt);
va_format(res, fmt, va);
va_end(va);
#if LL_WINDOWS
// made converting to utf8. See EXT-8318.
res = ll_convert_string_to_utf8_string(res);
#endif
return res;
}

View File

@@ -40,6 +40,9 @@
// *NOTE: buffer limited to 1024, (but vsnprintf prevents overrun)
// should perhaps be replaced with boost::format.
LL_COMMON_API std::string llformat(const char *fmt, ...);
std::string LL_COMMON_API llformat(const char *fmt, ...);
// the same version as above but ensures that returned string is in utf8 on windows
// to enable correct converting utf8_to_wstring.
std::string LL_COMMON_API llformat_to_utf8(const char *fmt, ...);
#endif // LL_LLFORMAT_H

View File

@@ -83,7 +83,7 @@ documentation and/or software.
#include "llmd5.h"
#include <cassert>
#include <iostream>
#include <iostream> // cerr
// how many bytes to grab at a time when checking files
const int LLMD5::BLOCK_LEN = 4096;

View File

@@ -71,7 +71,7 @@ void LLMetricsImpl::recordEventDetails(const std::string& location,
metrics["location"] = location;
metrics["stats"] = stats;
llinfos << "LLMETRICS: " << LLSDNotationStreamer(metrics) << llendl;
llinfos << "LLMETRICS: " << (LLSDNotationStreamer(metrics)) << llendl;
}
// Store this:

View File

@@ -64,6 +64,11 @@ void LLProcessLauncher::setWorkingDirectory(const std::string &dir)
mWorkingDir = dir;
}
const std::string& LLProcessLauncher::getExecutable() const
{
return mExecutable;
}
void LLProcessLauncher::clearArguments()
{
mLaunchArguments.clear();

View File

@@ -53,6 +53,8 @@ public:
void setExecutable(const std::string &executable);
void setWorkingDirectory(const std::string &dir);
const std::string& getExecutable() const;
void clearArguments();
void addArgument(const std::string &arg);
void addArgument(const char *arg);

View File

@@ -65,32 +65,32 @@
/**
*@brief Generate a float from [0, RAND_MAX).
*/
LL_COMMON_API S32 ll_rand();
S32 LL_COMMON_API ll_rand();
/**
*@brief Generate a float from [0, val) or (val, 0].
*/
LL_COMMON_API S32 ll_rand(S32 val);
S32 LL_COMMON_API ll_rand(S32 val);
/**
*@brief Generate a float from [0, 1.0).
*/
LL_COMMON_API F32 ll_frand();
F32 LL_COMMON_API ll_frand();
/**
*@brief Generate a float from [0, val) or (val, 0].
*/
LL_COMMON_API F32 ll_frand(F32 val);
F32 LL_COMMON_API ll_frand(F32 val);
/**
*@brief Generate a double from [0, 1.0).
*/
LL_COMMON_API F64 ll_drand();
F64 LL_COMMON_API ll_drand();
/**
*@brief Generate a double from [0, val) or (val, 0].
*/
LL_COMMON_API F64 ll_drand(F64 val);
F64 LL_COMMON_API ll_drand(F64 val);
/**
* @brief typedefs for good boost lagged fibonacci.

View File

@@ -436,7 +436,7 @@ void get_keyword_and_value(std::string& keyword,
while (line_index < line_size)
{
c = line[line_index];
if (!isspace(c))
if (!LLStringOps::isSpace(c))
{
break;
}
@@ -448,7 +448,7 @@ void get_keyword_and_value(std::string& keyword,
while (line_index < line_size)
{
c = line[line_index];
if (isspace(c) || '\r' == c || '\n' == c)
if (LLStringOps::isSpace(c) || '\r' == c || '\n' == c)
{
break;
}

View File

@@ -38,6 +38,23 @@
LLStringTable gStringTable(32768);
LLStringTableEntry::LLStringTableEntry(const char *str)
: mString(NULL), mCount(1)
{
// Copy string
U32 length = (U32)strlen(str) + 1; /*Flawfinder: ignore*/
length = llmin(length, MAX_STRINGS_LENGTH);
mString = new char[length];
strncpy(mString, str, length); /*Flawfinder: ignore*/
mString[length - 1] = 0;
}
LLStringTableEntry::~LLStringTableEntry()
{
delete [] mString;
mCount = 0;
}
LLStringTable::LLStringTable(int tablesize)
: mUniqueEntries(0)
{

View File

@@ -49,11 +49,11 @@
#endif
#if STRING_TABLE_HASH_MAP
#if LL_WINDOWS
#include <hash_map>
#else
#include <ext/hash_map>
#endif
# if LL_WINDOWS
# include <hash_map>
# else
# include <ext/hash_map>
# endif
#endif
const U32 MAX_STRINGS_LENGTH = 256;
@@ -61,21 +61,9 @@ const U32 MAX_STRINGS_LENGTH = 256;
class LL_COMMON_API LLStringTableEntry
{
public:
LLStringTableEntry(const char *str)
: mString(NULL), mCount(1)
{
// Copy string
U32 length = (U32)strlen(str) + 1; /*Flawfinder: ignore*/
length = llmin(length, MAX_STRINGS_LENGTH);
mString = new char[length];
strncpy(mString, str, length); /*Flawfinder: ignore*/
mString[length - 1] = 0;
}
~LLStringTableEntry()
{
delete [] mString;
mCount = 0;
}
LLStringTableEntry(const char *str);
~LLStringTableEntry();
void incCount() { mCount++; }
BOOL decCount() { return --mCount; }

View File

@@ -74,7 +74,7 @@ extern int errno;
static const S32 CPUINFO_BUFFER_SIZE = 16383;
LL_COMMON_API LLCPUInfo gSysCPU;
LLCPUInfo gSysCPU;
#if LL_WINDOWS
#ifndef DLLVERSIONINFO

View File

@@ -131,10 +131,10 @@ LL_COMMON_API std::ostream& operator<<(std::ostream& s, const LLCPUInfo& info);
LL_COMMON_API std::ostream& operator<<(std::ostream& s, const LLMemoryInfo& info);
// gunzip srcfile into dstfile. Returns FALSE on error.
LL_COMMON_API BOOL gunzip_file(const std::string& srcfile, const std::string& dstfile);
BOOL LL_COMMON_API gunzip_file(const std::string& srcfile, const std::string& dstfile);
// gzip srcfile into dstfile. Returns FALSE on error.
LL_COMMON_API BOOL gzip_file(const std::string& srcfile, const std::string& dstfile);
BOOL LL_COMMON_API gzip_file(const std::string& srcfile, const std::string& dstfile);
LL_COMMON_API extern LLCPUInfo gSysCPU;
extern LL_COMMON_API LLCPUInfo gSysCPU;
#endif // LL_LLSYS_H

View File

@@ -908,8 +908,7 @@ mParent(parent)
else
{
LLNotificationChannelPtr p = LLNotifications::instance().getChannel(parent);
LLStandardSignal::slot_type f = boost::bind(&LLNotificationChannelBase::updateItem, this, _1);
p->connectChanged(f);
p->connectChanged(boost::bind(&LLNotificationChannelBase::updateItem, this, _1));
}
}
@@ -1010,16 +1009,18 @@ bool LLNotifications::uniqueFilter(LLNotificationPtr pNotif)
bool LLNotifications::uniqueHandler(const LLSD& payload)
{
std::string cmd = payload["sigtype"];
LLNotificationPtr pNotif = LLNotifications::instance().find(payload["id"].asUUID());
if (pNotif && pNotif->hasUniquenessConstraints())
{
if (payload["sigtype"].asString() == "add")
if (cmd == "add")
{
// not a duplicate according to uniqueness criteria, so we keep it
// and store it for future uniqueness checks
mUniqueNotifications.insert(std::make_pair(pNotif->getName(), pNotif));
}
else if (payload["sigtype"].asString() == "delete")
else if (cmd == "delete")
{
mUniqueNotifications.erase(pNotif->getName());
}
@@ -1425,6 +1426,8 @@ LLNotificationPtr LLNotifications::add(const LLNotification::Params& p)
void LLNotifications::add(const LLNotificationPtr pNotif)
{
if (pNotif == NULL) return;
// first see if we already have it -- if so, that's a problem
LLNotificationSet::iterator it=mItems.find(pNotif);
if (it != mItems.end())
@@ -1437,6 +1440,8 @@ void LLNotifications::add(const LLNotificationPtr pNotif)
void LLNotifications::cancel(LLNotificationPtr pNotif)
{
if (pNotif == NULL || pNotif->isCancelled()) return;
LLNotificationSet::iterator it=mItems.find(pNotif);
if (it == mItems.end())
{