• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kig

Classes | Public Types | Public Member Functions | List of all members
ArgsParser Class Reference

#include <argsparser.h>

Classes

struct  spec
 

Public Types

enum  { Invalid = 0, Valid = 1, Complete = 2 }
 

Public Member Functions

 ArgsParser (const struct spec *args, int n)
 
 ArgsParser (const std::vector< spec > &args)
 
 ArgsParser ()
 
 ~ArgsParser ()
 
int check (const Args &os) const
 
int check (const std::vector< ObjectCalcer * > &os) const
 
bool checkArgs (const std::vector< ObjectCalcer * > &os) const
 
bool checkArgs (const std::vector< ObjectCalcer * > &os, uint minobjects) const
 
bool checkArgs (const Args &os) const
 
bool checkArgs (const Args &os, uint minobjects) const
 
const ObjectImpType * impRequirement (const ObjectImp *o, const Args &parents) const
 
void initialize (const std::vector< spec > &args)
 
void initialize (const struct spec *args, int n)
 
bool isDefinedOnOrThrough (const ObjectImp *o, const Args &parents) const
 
Args parse (const Args &os) const
 
std::vector< ObjectCalcer * > parse (const std::vector< ObjectCalcer * > &os) const
 
std::string selectStatement (const Args &sel) const
 
std::string usetext (const ObjectImp *o, const Args &sel) const
 
ArgsParser without (const ObjectImpType *type) const
 

Detailed Description

This class is meant to take care of checking the types of the parents to ObjectCalcer's, and to put them in the correct order.

An ObjectType should construct an ArgsParser with a specification of the arguments it wants. This specification is given as an array of ArgsParser::spec structs. This struct contains a pointer to an ObjectImpType ( which is the type you want the argument to have ), a string ( which is an I18N_NOOP'd string describing what you will be using the argument for ) and a boolean ( which says whether the constructed object is by construction on the curve argument ( if the constructed object is a point ), or whether the constructed object is by construction through the point argument ( if the constructed object is a curve ) ).

An ObjectType using an ArgsParser to take care of the various things that it can handle ( impRequirement, the sortArgs functions and the isDefinedOnOrThrough stuff ), should inherit from ArgsParserObjectType, which takes care of calling the ArgsParser for these things... It also allows you to use a convenient ObjectConstructor for your type.

E.g., let's see what CircleBCPType has for its arguments spec: here's some code:

static const ArgsParser::spec argsspecTranslation[] =
{
{ ObjectImp::stype(), I18N_NOOP("Translate this object"), false },
{ VectorImp::stype(), I18N_NOOP("Translate by this vector"), false }
};
TranslatedType::TranslatedType()
: ArgsParserObjectType( "Translation", argsspecTranslation, 2 )
{
}
ObjectImp* TranslatedType::calc( const Args& args, const KigDocument& ) const
{
if ( ! margsparser.checkArgs( args ) ) return new InvalidImp;
Coordinate dir = static_cast<const VectorImp*>( args[1] )->dir();
Transformation t = Transformation::translation( dir );
return args[0]->transform( t );
}

As you can see above, the argsspec can be declared right in the cpp-file. The usetexts explain to the user what the argument in question will be used for. The boolean says that in this case, the constructed object is not by construction on or through one of its arguments. In the constructor, you simply call the ArgsParserObjectType with the argsspec struct you defined, and the number of arguments in the argsspec ( in this case 2 ).

In the calc function, you can rely on the arguments already being in the correct order ( the same order as you put them in in the arguments spec. You should use the checkArgs function to check if all the arguments are valid, and if they aren't return a InvalidImp. All objects can always become invalid ( e.g. an intersection point of two non-intersecting conics can become valid again when the conics move ), and you should always check for this.

An interesting to note here is that the first argument is of a more general type than the second. A VectorImp is also an ObjectImp. In general, when this happens, you should put the more general type first, as in general this produces the results that the user expects. I have no formal proof for this, just talking from experience. It might be that you experience different things, but unless you're sure of the results, put the more general type first.

This class uses a pretty basic algorithm for doing the parsing ( e.g. if a match fails in one order, it does not try a different order, which could perhaps be necessary in the case of having more general argument types in the same argument spec ). However, the current algorithm works in all the situation where I've tested it, and I don't feel the need to change it. Feel free to do so if you like, but even if you do, I'm not sure if I will include it in mainline Kig.

Definition at line 106 of file argsparser.h.

Member Enumeration Documentation

anonymous enum

this are some enum values that we return from some functions.

Enumerator
Invalid 
Valid 
Complete 

Definition at line 112 of file argsparser.h.

Constructor & Destructor Documentation

ArgsParser::ArgsParser ( const struct spec *  args,
int  n 
)
ArgsParser::ArgsParser ( const std::vector< spec > &  args)

Definition at line 37 of file argsparser.cpp.

ArgsParser::ArgsParser ( )

Definition at line 33 of file argsparser.cpp.

ArgsParser::~ArgsParser ( )

Definition at line 232 of file argsparser.cpp.

Member Function Documentation

int ArgsParser::check ( const Args &  os) const

Definition at line 99 of file argsparser.cpp.

int ArgsParser::check ( const std::vector< ObjectCalcer * > &  os) const

Definition at line 104 of file argsparser.cpp.

bool ArgsParser::checkArgs ( const std::vector< ObjectCalcer * > &  os) const

Definition at line 222 of file argsparser.cpp.

bool ArgsParser::checkArgs ( const std::vector< ObjectCalcer * > &  os,
uint  minobjects 
) const

Definition at line 227 of file argsparser.cpp.

bool ArgsParser::checkArgs ( const Args &  os) const

Definition at line 212 of file argsparser.cpp.

bool ArgsParser::checkArgs ( const Args &  os,
uint  minobjects 
) const

Definition at line 217 of file argsparser.cpp.

const ObjectImpType * ArgsParser::impRequirement ( const ObjectImp *  o,
const Args &  parents 
) const

returns the minimal ObjectImp ID that o needs to inherit in order to be useful.

. o should be part of parents .

Definition at line 185 of file argsparser.cpp.

void ArgsParser::initialize ( const std::vector< spec > &  args)

Definition at line 42 of file argsparser.cpp.

void ArgsParser::initialize ( const struct spec *  args,
int  n 
)

Definition at line 27 of file argsparser.cpp.

bool ArgsParser::isDefinedOnOrThrough ( const ObjectImp *  o,
const Args &  parents 
) const

Supposing that parents would be given as parents, this function returns whether the returned ObjectImp will be, by construction, on o ( if o is a curve ), or through o ( if o is a point ).

Definition at line 236 of file argsparser.cpp.

Args ArgsParser::parse ( const Args &  os) const

Definition at line 135 of file argsparser.cpp.

std::vector< ObjectCalcer * > ArgsParser::parse ( const std::vector< ObjectCalcer * > &  os) const

Definition at line 140 of file argsparser.cpp.

std::string ArgsParser::selectStatement ( const Args &  sel) const

returns the select statement for the next selectable argument when the given args are selected.

Definition at line 242 of file argsparser.cpp.

std::string ArgsParser::usetext ( const ObjectImp *  o,
const Args &  sel 
) const

returns the usetext for the argument that o would be used for, if sel were used as parents.

o should be in sel ...

Definition at line 192 of file argsparser.cpp.

ArgsParser ArgsParser::without ( const ObjectImpType *  type) const

returns a new ArgsParser that wants the same args, except for the ones of the given type.

Definition at line 145 of file argsparser.cpp.


The documentation for this class was generated from the following files:
  • argsparser.h
  • argsparser.cpp
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:35:40 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kig

Skip menu "kig"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal