29 #include <QStringList> 36 #include <QTextFormat> 54 bool operator()(
const Value& a,
const Value& b) {
return a == b; }
66 Qt::CaseSensitivity cs;
81 template<
class Key,
class Value,
class ValCompareFunc>
86 for (iter = a.
begin(); iter != a.
end(); ++iter) {
176 for (k = 0; k < list.
size(); ++k)
177 l << QVariant::fromValue<T>(list[k]);
188 for (k = 0; k < vlist.size(); ++k) {
189 list << vlist[k].
value<T>();
198 vmap[it.key()] = QVariant::fromValue<T>(it.value());
208 for (QVariantMap::const_iterator it = vmap.begin(); it != vmap.end(); ++it) {
209 map[it.key()] = it.
value().value<T>();
420 bool recursive =
true);
451 template<
class T,
class MapOp>
467 return templ.
arg(str);
495 template<
class Value>
498 template<
class Value>
503 for (k = 0; x[k].
key != NULL; ++k) {
527 virtual void setTarget(
KLFTarget *target);
637 const T *
ptr()
const {
return p; }
644 klfDbg(
"new pointer: "<<newptr<<
"; old pointer was "<<p) ;
660 autodelete = other.autodelete;
666 setPointer((T*)(aptr));
696 inline operator T *()
698 inline operator const T *()
const 716 template<
class OtherPtr>
717 inline OtherPtr
dyn_cast() {
return dynamic_cast<OtherPtr
>(p); }
719 template<
class OtherPtr>
720 inline const OtherPtr
dyn_cast()
const {
return dynamic_cast<const OtherPtr
>(p); }
723 {
return (
void *)p == otherptr; }
726 {
return p == otherptr.p; }
736 void operator+=(
int ) { }
737 void operator-=(
int ) { }
749 klfDbg(p<<
": deref()! n="<<n<<
"; autodelete="<<autodelete) ;
750 if (autodelete && n <= 0) {
751 klfDbg(
"Deleting at refcount="<<n<<
".") ;
762 klfDbg(p<<
": ref()! n="<<n) ;
784 int ref() {
return ++refcount; }
851 ptrguard = copy.ptrguard;
860 if (ptrguard == NULL)
862 return (Pointer) ptrguard->ptr;
867 inline operator const T*()
892 if (ptrguard != NULL) {
893 klfWarning(
"Leaving tracked pointer "<<ptrguard->ptr<<
" for another pointer!") ;
897 ptrguard->
ptr = (
void*)p;
903 KLF_ASSERT_CONDITION(ptrguard == NULL,
"Leaving tracked pointer "<<ptrguard->ptr<<
" for a copy pointer!",
905 ptrguard = copy.ptrguard;
911 if (ptrguard != NULL)
912 ptrguard->ptr = NULL;
949 return QVariant::fromValue<T>(value);
953 return variant.
value<T>();
964 return klfVariantListToList<T>(variant.
toList());
971 return QVariant::fromValue<QTextFormat>(value);
985 #define KLFTOOLS_INIT \ 986 Q_INIT_RESOURCE(klftoolsres)
KLF_EXPORT uint klfUrlCompare(const QUrl &url1, const QUrl &url2, uint interestFlags=0xffffffff, const QStringList &interestQueryItems=QStringList())
Compares two URLs and returns some flags as to how they differ.
KLF_EXPORT QString klfSearchPath(const QString &prog, const QString &extra_path="")
Smart executable searching in a given path list with wildcards.
Merge environments by expanding new values according to current environment.
KLF_EXPORT bool klfMatch(const QVariant &testForHitCandidateValue, const QVariant &queryValue, Qt::MatchFlags flags, const QString &queryStringCache=QString())
Generalized value matching.
KLF_EXPORT QString klfPrefixedPath(const QString &path, const QString &reference=QString())
Returns absolute path to path as seen from reference.
bool contains(const Key &key) const
Store a guarded pointer, synchronizing other copies of this pointer.
Prepend given value to list of path items.
implements an equality tester between strings
klfStrCaseEqualFunc(Qt::CaseSensitivity caseSensitive)
Remove duplicates from the variable.
KLFRefPtr(const KLFRefPtr ©)
void setPointer(Pointer newptr)
const T * operator->() const
bool operator()(const Value &a, const Value &b)
QList< QVariant > toList() const
Base declarations for klatexformula and some utilities.
bool klfMapIsIncludedIn(const QMap< Key, Value > &a, const QMap< Key, Value > &b, ValCompareFunc cfunc=klfEqualFunc< Value >())
Compares two QMap's for inclusion.
QMap< QString, Value > klfMakeMap(KLFMapInitData< Value > x[])
#define klfDbg(streamableItems)
print debug stream items
#define KLF_DEBUG_BLOCK(msg)
Utility to debug the execution of a block.
QList< T > klfMkList(const T &a)
static QTextCharFormat recover(const QVariant &variant)
bool operator==(void *otherptr) const
bool operator!=(void *otherptr) const
const T & operator*() const
KLF_EXPORT QStringList klfCurrentEnvironment()
Returns the current system's environment.
static QList< T > recover(const QVariant &variant)
KlfUrlCompareFlag
Some relevant values for klfUrlCompare()
Pointer operator=(Pointer p)
If we're expanding new environment variables, don't expand them recursively.
QMap< QString, T > klfVariantMapToMap(const QVariantMap &vmap)
Urls are equal. The order of query items may be different, but the same are given with the same value...
QStringList klfMapStringList(const QStringList &list, const QString &mapstr)
KLF_EXPORT QStringList klfGetEnvironmentPath(const QStringList &env, const QString &var=QLatin1String("PATH"))
get the path items of an environment variable (commonly $PATH)
Append given path items to current list.
KLFRefPtr< T > & operator=(const KLFRefPtr< T > &other)
QString fromUtf8(const char *str, int size)
bool operator==(const KLFRefPtr< T > &otherptr) const
#define klfWarning(streamableItems)
bool operator==(const KLFPropertizedObject &a, const KLFPropertizedObject &b)
KLF_EXPORT void klfMergeEnvironment(QStringList *env, const QStringList &addvars, const QStringList &pathvars=QStringList(), uint mergeaction=KlfEnvPathPrepend)
merge two environment definitions
KLF_EXPORT QString klfUrlLocalFilePath(const QUrl &url)
KLF_EXPORT QString klfSetEnvironmentPath(const QString &oldpaths, const QString &newpaths, uint action=KlfEnvPathAppend|KlfEnvPathNoDuplicates)
set/add path items to a PATH-like environment variable (commonly $PATH)
QVariantMap klfMapToVariantMap(const QMap< QString, T > &map)
bool operator()(const QString &a, const QString &b)
KLFSyncGuardPtr(const KLFSyncGuardPtr ©)
QList< T > klfListMap(const QList< T > &list, MapOp op)
Don't take any action, just apply flags.
void setAutoDelete(bool on)
const KLFSyncGuardPtr & operator=(const KLFSyncGuardPtr ©)
KLF_EXPORT bool klfEnsureDir(const QString &dir)
Ensure existence of a directory.
KLF_EXPORT QString klfJoinEnvironmentPath(const QStringList &paths)
join several paths together to form a PATH-like environment variable value (common for $PATH) ...
This is NOT a specific test. It modifies the behavior of klfUrlCompare() by instructing it to compare...
Stores a pointer to an object with refcount.
Urls have same base URL. All query items in url1 are present in url2 with the same values...
static QVariant convert(const T &value)
KLF_EXPORT QMap< QString, QString > klfEnvironmentListToMap(const QStringList &env)
convert environment list into a map of variable names to values
Mask out the requested action.
QString operator()(const QString &str)
KLF_EXPORT QString klfGetEnvironmentVariable(const QStringList &env, const QString &var)
returns the value of an environment variable, defined in env.
QList< KLFTargeter * > pTargetOf
KLF_EXPORT QStringList klfSearchFind(const QString &wildcard_expression, int limit=-1)
Find files matching a path with wildcards.
KLFRefPtr< T > & operator=(Pointer newptr)
KLF_EXPORT QString klfExpandEnvironmentVariables(const QString &expression, const QStringList &env=QStringList(), bool recursive=true)
Expands references to environment variables to their values.
KLF_EXPORT QStringList klfMapToEnvironmentList(const QMap< QString, QString > &map)
convert a map of variable names to values to an environment list
KLF_EXPORT void klfSetEnvironmentVariable(QStringList *env, const QString &var, const QString &value)
set the value of a variable in environment variables list, replacing existing definition if any...
static QVariant convert(const QList< T > &list)
__klf_StrArg_MapOp(const QString &t)
Mask out the merge actions flags.
QVariantList klfListToVariantList(const QList< T > &list)
const T * operator()() const
Urls have same base URL. All query items in url2 are present in url1 with the same values...
QList< T > klfVariantListToList(const QVariantList &vlist)
bool operator!=(const KLFRefPtr< T > &otherptr) const
static T recover(const QVariant &variant)
KLFRefPtr< T > & operator=(OtherPtr aptr)
#define KLF_ASSERT_CONDITION(expr, msg, failaction)
Asserting Conditions (NON-FATAL)
Replace current path items by given ones.
const OtherPtr dyn_cast() const
int compare(const QString &other, Qt::CaseSensitivity cs) const
Pointer operator->() const
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const
static QVariant convert(const QTextCharFormat &value)
Implements default equality tester with operator==.
KlfEnvAction
Used in klfMergeEnvironment() and klfSetEnvironmentPath().
const T * operator()() const
KLF_EXPORT QStringList klfSplitEnvironmentPath(const QString &value)
split the value of a PATH-like environment variable into paths (common for $PATH) ...
const T value(const Key &key, const T &defaultValue) const
Urls have same base URL. Query items are ignored.