lib Library API Documentation

KSUtil Class Reference

Utility functions for checking arguments and creating exceptions. More...

#include <koscript_util.h>

List of all members.

Static Public Member Functions

static bool checkArgumentsCount (KSContext &context, uint count, const QString &method, bool fatal=true)
static bool checkType (KSContext &context, KSValue *v, KSValue::Type t, bool fatal=true)
static bool checkType (KSContext &context, const KSValue::Ptr &v, KSValue::Type t, bool fatal=true)
static void castingError (KSContext &context, KSValue *v, KSValue::Type t)
static void castingError (KSContext &context, const QString &from, const QString &to)
static void argumentsMismatchError (KSContext &context, const QString &methodname)
static void tooFewArgumentsError (KSContext &context, const QString &methodname)
static void tooManyArgumentsError (KSContext &context, const QString &methodname)
static bool checkArgs (KSContext &context, const QCString &signature, const QString &method, bool fatal=TRUE)
static bool checkArgs (KSContext &context, const QValueList< KSValue::Ptr > &args, const QCString &signature, const QString &method, bool fatal=TRUE)
static bool checkArg (KSContext &context, const KSValue::Ptr &arg, const QCString &signature, const QString &method="", bool fatal=FALSE)


Detailed Description

Utility functions for checking arguments and creating exceptions.

Author:
Torben Weis <weis@kde.org>

Definition at line 36 of file koscript_util.h.


Member Function Documentation

bool KSUtil::checkArgumentsCount KSContext &  context,
uint  count,
const QString method,
bool  fatal = true
[static]
 

Checks whether method has enough arguments (count).

Returns:
TRUE on success, otherwise FALSE and raises one of tooFewArgumentsError or tooManyArgumentsError exceptions

Definition at line 25 of file koscript_util.cc.

References tooFewArgumentsError(), and tooManyArgumentsError().

bool KSUtil::checkType KSContext &  context,
KSValue v,
KSValue::Type  t,
bool  fatal = true
[static]
 

Returns:
TRUE if the value matches the requested type t or if KSValue will seamlessly convert to that type.
Parameters:
context is used if fatal is TRUE and an exception has to be created.
v is the value that is to be tested.
t is the type v has to match.
fatal determines whether an exception is set on error.

Definition at line 45 of file koscript_util.cc.

References castingError(), and KSValue::implicitCast().

Referenced by checkArg(), and checkArgs().

bool KSUtil::checkType KSContext &  context,
const KSValue::Ptr v,
KSValue::Type  t,
bool  fatal = true
[static]
 

Returns:
TRUE if the value matches the requested type t or if KSValue will seamlessly convert to that type.
Parameters:
context is used if fatal is TRUE and an exception has to be created.
v is the value that is to be tested.
t is the type v has to match.
fatal determines whether an exception is set on error.

Definition at line 59 of file koscript_util.cc.

References castingError().

void KSUtil::castingError KSContext &  context,
KSValue v,
KSValue::Type  t
[static]
 

Creates an exception for context telling that the value v did not match the type t.

Definition at line 79 of file koscript_util.cc.

References KSValue::typeName().

Referenced by checkArg(), checkArgs(), and checkType().

void KSUtil::castingError KSContext &  context,
const QString from,
const QString to
[static]
 

Creates an exception for context telling that the type from was requested but to appreaed.

Definition at line 73 of file koscript_util.cc.

void KSUtil::argumentsMismatchError KSContext &  context,
const QString methodname
[static]
 

Creates an exception for context telling that the passed parameters do not match the methods signature.

Definition at line 85 of file koscript_util.cc.

void KSUtil::tooFewArgumentsError KSContext &  context,
const QString methodname
[static]
 

Creates an exception for context telling that there were too few arguments in the call to method methodname.

Definition at line 91 of file koscript_util.cc.

Referenced by checkArgs(), and checkArgumentsCount().

void KSUtil::tooManyArgumentsError KSContext &  context,
const QString methodname
[static]
 

Creates an exception for context telling that there were too many arguments in the call to method methodname.

Definition at line 97 of file koscript_util.cc.

Referenced by checkArgumentsCount().

bool KSUtil::checkArgs KSContext &  context,
const QCString signature,
const QString method,
bool  fatal = TRUE
[static]
 

A convenience function that extracts the arguemnts out of "context.value()".

It checks whether this value is really a list.

Definition at line 103 of file koscript_util.cc.

References checkType().

bool KSUtil::checkArgs KSContext &  context,
const QValueList< KSValue::Ptr > &  args,
const QCString signature,
const QString method,
bool  fatal = TRUE
[static]
 

Checks whether the argument list passed in args matches the signature.

Parameters:
context is used if fatal is TRUE and an exception has to be created.
args is the list of arguments.
signature is the functions signature (see below)
method is the name of the method for which we test the argument list.
fatal determines whether an exception is set on error.
Returns:
TRUE if the check was successful.
The signature is a sequence of the following characters:
  • f = float
  • b = bool
  • s = string
  • i = integer
  • [] = a list
  • {} = a map
  • Om:n; = An object of module "m" and name "n".
  • Sm:n; = An struct of module "m" and name "n".
You may put "|" between the characters. This means that the list of arguments may end now. If there are still arguments left then they have to match with the rest of the signature.

Example: "iSqt:QRect;f|b" is a signature that takes 1) an integer 2) a struct named "QRect" in module "qt" 3) a float 4) an optional boolean

Definition at line 111 of file koscript_util.cc.

References castingError(), checkType(), and tooFewArgumentsError().

bool KSUtil::checkArg KSContext &  context,
const KSValue::Ptr arg,
const QCString signature,
const QString method = "",
bool  fatal = FALSE
[static]
 

Checks whether the argument passed in args matches the signature.

Parameters:
context is used if fatal is TRUE and an exception has to be created.
arg is the argument to check
signature is the functions signature (see below)
method is the name of the method for which we test the argument list.
fatal determines whether an exception is set on error.
Returns:
TRUE if the check was successful.
The signature is a sequence of the following characters:
  • f = float
  • b = bool
  • s = string
  • i = integer
  • [] = a list
  • {} = a map
  • Om:n; = An object of module "m" and name "n".
  • Sm:n; = An struct of module "m" and name "n".

Example: "Sqt:QRect;" is a signature that takes a struct named "QRect" in module "qt"

Definition at line 206 of file koscript_util.cc.

References castingError(), and checkType().


The documentation for this class was generated from the following files:
KDE Logo
This file is part of the documentation for lib Library Version 1.4.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Mon Feb 13 09:42:01 2006 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003