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

bool checkArgumentsCount (KSContext &context, uint count, const QString &method, bool fatal=true)
bool checkType (KSContext &context, KSValue *v, KSValue::Type t, bool fatal=true)
bool checkType (KSContext &context, const KSValue::Ptr &v, KSValue::Type t, bool fatal=true)
void castingError (KSContext &context, KSValue *v, KSValue::Type t)
void castingError (KSContext &context, const QString &from, const QString &to)
void argumentsMismatchError (KSContext &context, const QString &methodname)
void tooFewArgumentsError (KSContext &context, const QString &methodname)
void tooManyArgumentsError (KSContext &context, const QString &methodname)
bool checkArgs (KSContext &context, const QCString &signature, const QString &method, bool fatal=TRUE)
bool checkArgs (KSContext &context, const QValueList< KSValue::Ptr > &args, const QCString &signature, const QString &method, bool fatal=TRUE)
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 35 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 checkArgumentsCount(), tooFewArgumentsError(), and tooManyArgumentsError().

Referenced by checkArgumentsCount().

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(), checkType(), and KSValue::implicitCast().

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

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(), and checkType().

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 castingError(), and KSValue::typeName().

Referenced by castingError(), 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.

References castingError().

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.

References argumentsMismatchError().

Referenced by argumentsMismatchError().

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.

References tooFewArgumentsError().

Referenced by checkArgs(), checkArgumentsCount(), and tooFewArgumentsError().

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.

References tooManyArgumentsError().

Referenced by checkArgumentsCount(), and tooManyArgumentsError().

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 checkArgs(), and checkType().

Referenced by checkArgs().

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(), checkArgs(), 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(), checkArg(), and checkType().

Referenced by checkArg().


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.3.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Sep 28 04:04:06 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003