[KLF Backend][KLF Tools][KLF Home]
KLatexFormula Project
Defines | Functions
src/klftools/klfdefs.h File Reference

Base declarations for klatexformula and some utilities. More...

#include <QObject>
#include <QString>
#include <QVariant>
#include <klfdebug.h>
Include dependency graph for klfdefs.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define klfFmtCC
#define klfFmtDoubleCC   (const char*)klfFmtDouble
#define KLF_FUNC_SINGLE_RUN
 Simple test for one-time-run functions.
#define KLF_DECLARE_PRIVATE(ClassName)
#define KLF_PRIVATE_HEAD(ClassName)
#define KLF_PRIVATE_INHERIT_HEAD(ClassName, BaseInit)
#define KLF_PRIVATE_QOBJ_HEAD(ClassName, QObj)
#define KLF_INIT_PRIVATE(ClassName)
#define KLF_DELETE_PRIVATE
#define KLF_BLOCK   for (bool _klf_block_first = true; _klf_block_first; _klf_block_first = false)
#define KLF_TRY(expr, msg, failaction)
#define KLF_DEFINE_PROPERTY_GET(ClassName, type, prop)
#define KLF_DEFINE_PROPERTY_GETSET(ClassName, type, prop, Prop)
#define KLF_DEFINE_PROPERTY_GETSET_C(ClassName, type, prop, Prop)

Functions

KLF_EXPORT const char * klfVersion ()
KLF_EXPORT int klfVersionMaj ()
KLF_EXPORT int klfVersionMin ()
KLF_EXPORT int klfVersionRelease ()
KLF_EXPORT QByteArray klfFmt (const char *fmt,...)
KLF_EXPORT QByteArray klfFmt (const char *fmt, va_list pp)
KLF_EXPORT QByteArray klfFmtDouble (double num, char fmt= 'g', int precision=6)
KLF_EXPORT bool klfIsValidVersion (const QString &v)
KLF_EXPORT int klfVersionCompare (const QString &v1, const QString &v2)
 Compares two version strings.
KLF_EXPORT bool klfVersionCompareLessThan (const QString &v1, const QString &v2)
 Same as klfVersionCompare(v1,v2) < 0

Detailed Description

Base declarations for klatexformula and some utilities.

Definition in file klfdefs.h.


Define Documentation

#define KLF_BLOCK   for (bool _klf_block_first = true; _klf_block_first; _klf_block_first = false)

Definition at line 100 of file klfdefs.h.

#define KLF_DECLARE_PRIVATE (   ClassName)

To be used inside a class declaration. Declares a private member pointer d as type ClassNamePrivate *.

Minimal Example:

  // myclass.h
  // ...
  class MyClassPrivate;
  class MyClass {
  public:
    MyClass(...);
    ~MyClass(...);
    // ...
    some_method();
    // ...
    KLF_DECLARE_PRIVATE(MyClass) ;
  }

  // myclass.cpp
  struct MyClassPrivate {
    KLF_PRIVATE_HEAD(MyClass) {
      // initialize our properties, this is the constructor
      someproperty = false;
    }

    bool someproperty;

    void somelocalmethod() {
      // can access MyClass instance with the 'K' pointer object
      K->some_method();
    }
  }

  MyClass::MyClass()
  {
    KLF_INIT_PRIVATE(MyClass) ;    
  }
  MyClass::~MyClass()
  {
    KLF_DELETE_PRIVATE ;
  }
  MyClass::some_method()
  {
    // may access the private class as 'd' pointer
    do_something_with(d->someproperty);
  }
  // ...

See also KLF_PRIVATE_HEAD, KLF_INIT_PRIVATE, KLF_DELETE_PRIVATE.

Definition at line 74 of file klfdefs.h.

#define KLF_DEFINE_PROPERTY_GET (   ClassName,
  type,
  prop 
)

Use this to define a getter function (whose prototype matches one declared by KLF_PROPERTY_GETSET). The property value is assumed to be stored in a Private class instance as declared by KLF_DECLARE_PRIVATE and friends. The member name in the Private class is assumed to be exactly the property name.

This macro expands to

  <type> ClassName::<propertyName>() const { return d-><propertyName>; }

Definition at line 113 of file klfdefs.h.

#define KLF_DEFINE_PROPERTY_GETSET (   ClassName,
  type,
  prop,
  Prop 
)

Same as KLF_DEFINE_PROPERTY_GET, but also defines a setter function.

This macro expands to

  <type> ClassName::<propertyName>() const { return d-><propertyName>; }
  void ClassName::set<PropertyName>(<type> value) { d-><propertyName> = value; }

See also KLF_DEFINE_PROPERTY_GETSET_C.

Definition at line 116 of file klfdefs.h.

#define KLF_DEFINE_PROPERTY_GETSET_C (   ClassName,
  type,
  prop,
  Prop 
)

Same as KLF_DEFINE_PROPERTY_GETSET, but defines the setter with a const <type>& argument. Use this with properties of class type.

Definition at line 120 of file klfdefs.h.

Simple test for one-time-run functions.

Usage example:

 void init_load_stuff()
 {
   KLF_FUNC_SINGLE_RUN ;
   // ... eg. load some initializing data in a static structure ...
   // this operation will only be performed the first time that init_load_stuff() is called.
   // ...
 }

Definition at line 70 of file klfdefs.h.

#define KLF_INIT_PRIVATE (   ClassName)
#define KLF_PRIVATE_HEAD (   ClassName)

Declare the first lines with constructor of the private struct/class. This declaration must be followed by a pair of braces containing constructor content, like shown in the example given for KLF_DECLARE_PRIVATE.

This method makes sure a local pointer named K points back to the main class.

Definition at line 81 of file klfdefs.h.

#define KLF_PRIVATE_INHERIT_HEAD (   ClassName,
  BaseInit 
)
Value:
private: ClassName *K;                                          \
  public:  ClassName * parentClass() const { return K; }                  \
  public:  ClassName##Private (ClassName * ptr) BaseInit, K(ptr)

Definition at line 85 of file klfdefs.h.

#define KLF_PRIVATE_QOBJ_HEAD (   ClassName,
  QObj 
)

Same as KLF_PRIVATE_HEAD, except use this if your private class is a QObject subclass, and you want to initialize it with the parent being the main class instance. The pointer K is also initialized. You still have to manually include the Q_OBJECT macro into your definition.

Definition at line 89 of file klfdefs.h.

#define KLF_TRY (   expr,
  msg,
  failaction 
)
Value:
if ( !(expr) ) {                                                       \
    klfWarning(msg);                                                   \
    failaction;                                                        \
  }

Definition at line 103 of file klfdefs.h.

#define klfFmtCC

Same as klfFmt(), but returns the formatted string as a const char* C-style string.

Example:

  unsigned int flags = ... ;
  qDebug()<<"Flags are: "<<klfFmtCC("%#010x", flags) ;

Used in a QDebug stream, this function has the advantage (over klfFmt()) of not having its value enclosed in quotes.

Note for advanced usage
This macro, when called as klfFmtCC (format, args...) expands to

 (const char*)klfFmt (format, args...)  

Which means that if you are trying to do something (quite unorthodox) like:

   cout<<"3rd digit of 280 in base 8 is: "<< klfFmtCC("%o", 280)[2]; // does not compile

then it will fail at compile-time, since the const char* cast is evaluated after the operator[]. The working example is:

   cout<<"3rd digit of 280 in base 8 is: "<< (klfFmtCC("%o", 280))[2]; // correct

This macro had to be declared without any arguments, since C preprocessor macros don't support variable number of arguments (as required by printf-style formatting). This is the reason why I couldn't automatically fit in the extra required parenthesis in the macro definition.

Definition at line 61 of file klfdefs.h.

Referenced by KLFDebugObjectWatcher::debugObjectDestroyed(), klfDataToEscaped(), klfEscapedToData(), and KLFLatexSyntaxHighlighter::parsedBlocksForPos().

#define klfFmtDoubleCC   (const char*)klfFmtDouble

Definition at line 67 of file klfdefs.h.


Function Documentation

KLF_EXPORT QByteArray klfFmt ( const char *  fmt,
  ... 
)

Formats a printf-style string and returns the data as a QByteArray.

Warning:
the final string length must not exceed 8192 bytes, the size of the internal buffer.

Definition at line 1027 of file klfdefs.cpp.

References klfFmt().

KLF_EXPORT QByteArray klfFmt ( const char *  fmt,
va_list  pp 
)

Implements klfFmt(const char *, ...) functionality, but with a va_list argument pointer for use in vsprintf().

Definition at line 998 of file klfdefs.cpp.

References KLF_FUNC_NAME.

Referenced by klfFmt().

KLF_EXPORT QByteArray klfFmtDouble ( double  num,
char  fmt = 'g',
int  precision = 6 
)

Definition at line 1037 of file klfdefs.cpp.

References QString::number(), and QString::toLatin1().

KLF_EXPORT bool klfIsValidVersion ( const QString v)

Definition at line 1175 of file klfdefs.cpp.

References QRegExp::exactMatch(), and VERSION_RX.

KLF_EXPORT const char* klfVersion ( )

Returns the current version of the KLatexFormula library, given as a string, eg. "3.2.1".

For non-release builds, this may have a suffix, eg. "3.2.0beta2".

Definition at line 906 of file klfdefs.cpp.

KLF_EXPORT int klfVersionCompare ( const QString v1,
const QString v2 
)

Compares two version strings.

v1 and v2 must be of the form "<MAJ>.<MIN>.<REL><suffix>" or "<MAJ>.<MIN>.<REL>" or "<MAJ>.<MIN>" or "<MAJ>" or an empty string.

Empty strings are considered less than any other version string, except to other empty strings to which they compare equal.

Returns:
a negative value if v1 < v2, 0 if v1 == v2 and a positive value if v2 < v1. This function returns -200 if either of the version strings are invalid.

A less specific version number is considered as less than a more specific version number of equal common numbers, eg. "3.1" < "3.1.2".

When a suffix is appended to the version, it is attempted to be recognized:

  • "alpha" or "alphaN" is alpha version, eg. "3.1.1alpha2" < "3.1.1.alpha5" < "3.1.1"
  • "dev" is INTERNAL versioning, should not be published, it means further development after the given version number; for the next release, a higher version number has to be decided upon.
  • unrecognized suffixes are compared lexicographically, case sensitive.
  • after any non-empty suffix, you can add an optional integer number, which will be taken into account when comparing same version numbers with same suffix words, see examples below.

The full list of recognized suffixes is, in order from "least" to "most" recent version:

  • "a"
  • "alpha"
  • "b"
  • "beta"
  • "p"
  • "pre"
  • "preview"
  • "RC"
  • "rc"
  • "" ( version number specified without prefix)
  • "post"
  • "dev"
  • "devel"

Some examples, where "<" represents a logical "less than", characterized by this function returning a strictly negative value when called with both arguments:

   "3.1.0" < "3.1.2"
   "2" < "2.1" < "2.1.1"
   "3.0.0alpha2" < "3.0.0"
   "3.0.2" < "3.0.3alpha0"
   "3.2.0alpha" < "3.2.0beta"
   "3.2.0alpha" < "3.2.0alpha0"
   "3.2.0RC3" < "3.2.0RC4"
 

This function, when exchanging the arguments, returns a value that is of opposite sign, ie.

  klfVersionCompare(v1, v2)  ==  - klfVersionCompare(v2, v1)

Definition at line 1181 of file klfdefs.cpp.

References QRegExp::cap(), QRegExp::exactMatch(), QString::isEmpty(), QString::toInt(), and VERSION_RX.

Referenced by klfVersionCompareLessThan().

KLF_EXPORT bool klfVersionCompareLessThan ( const QString v1,
const QString v2 
)

Same as klfVersionCompare(v1,v2) < 0

Definition at line 1270 of file klfdefs.cpp.

References klfVersionCompare().

KLF_EXPORT int klfVersionMaj ( )

Returns the current major version of the KLatexFormula library.

For example, if the version is "3.2.0", klfVersionMaj() returns 3.

Definition at line 911 of file klfdefs.cpp.

KLF_EXPORT int klfVersionMin ( )

Returns the current minor version of the KLatexFormula library.

For example, if the version is "3.2.0", klfVersionMin() returns 2.

Definition at line 915 of file klfdefs.cpp.

KLF_EXPORT int klfVersionRelease ( )

Returns the current release version of the KLatexFormula library.

For example, if the version is "3.2.0", klfVersionRelease() returns 0.

Definition at line 919 of file klfdefs.cpp.


Generated by doxygen 1.7.6.1. The KLatexFormula website is hosted on sourceforge.net