/usr/include/Aria/ArConfigArg.h is in libaria-dev 2.8.0+repack-1.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 | /*
Adept MobileRobots Robotics Interface for Applications (ARIA)
Copyright (C) 2004, 2005 ActivMedia Robotics LLC
Copyright (C) 2006, 2007, 2008, 2009, 2010 MobileRobots Inc.
Copyright (C) 2011, 2012, 2013 Adept Technology
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
If you wish to redistribute ARIA under different terms, contact
Adept MobileRobots for information about a commercial version of ARIA at
robots@mobilerobots.com or
Adept MobileRobots, 10 Columbia Drive, Amherst, NH 03031; +1-603-881-7960
*/
#ifndef ARCONFIGARG_H
#define ARCONFIGARG_H
#include <map>
#include "ariaTypedefs.h"
#include "ariaUtil.h"
#include "ArFunctor.h"
class ArArgumentBuilder;
class ArFileParser;
/// Argument class for ArConfig
/**
ArConfigArg stores information about a parameter (name, description, type),
and a pointer to the variable that will actually store the value. This
variable is normally stored and used by whatever class or module has added the
parameter to ArConfig. (In addition, there are some special types of
ArConfigArg that behave differently such as the "holder" types and separator,
these are used internally or in special cases.)
Which constructor you use determines the value type of the ArConfigArg object.
A typical idiom for creating ArConfigArg objects and adding them to ArConfig
is to create a temporary ArConfigArg in the call to ArConfig::addParam():
@code
config->addParam(ArConfigArg("MyParameter", &myTarget, "Example Parameter"), "Example Section");
@endcode
Where <tt>config</tt> is a pointer to an ArConfig object or subclass, and
<tt>myTarget</tt> is a variable (e.g. int) that is a class member whose instance will not
be destroyed before the end of the program, or which will remove the parameter
from ArConfig before being destroyed (the pointer to <tt>myTarget</tt> that is stored
in ArConfig must not become invalid.) The ArConfigArg object passed to
addParam() will be copied and stored in ArConfig.
@swignote Swig cannot determine the correct constructor to use
based on most target langugages types, so you must use subclasses
defined for various types. Or, use the constructor that accepts
functors for dealing with arguments. Also, Swig cannot use pointers
to change variables, so you must create ArConfigArg objects, passing
in default values, and retain references to those objects,
in addition to passing them to ArConfig, and read new values from those
objects if ArConfig changes; or pass functors to ArConfigArg instead
of the initial value.
*/
class ArConfigArg
{
public:
typedef enum
{
INVALID, ///< An invalid argument, the argument wasn't created correctly
INT, ///< Integer argument
DOUBLE, ///< Double argument
STRING, ///< String argument
BOOL, ///< Boolean argument
FUNCTOR, ///< Argument that handles things with functors
DESCRIPTION_HOLDER, ///< Argument that just holds a description
STRING_HOLDER, ///< this one is for holding strings and reading them in and writing them out but not really letting them get sent anywhere (its for unknown config parameters (so they don't get lost if a feature is turned off)
SEPARATOR, ///< Empty argument that merely acts as a separator within a (large) section.
CPPSTRING, ///< Pointer to std::string, use like STRING.
LIST, ///< Composite argument that contains an ordered list of other args
LIST_HOLDER, ///< Placeholder for composite argument that are not currently active
LAST_TYPE = LIST_HOLDER ///< Last value in the enumeration
} Type;
/// Indicates the components that must be restarted if the parameter is changed
enum RestartLevel {
NO_RESTART, //< No restart necessary (default value)
RESTART_CLIENT, //< Client software must be restarted (TODO Can this be eliminated?)
RESTART_IO, //< IO has changed and needs to be restarted
RESTART_SOFTWARE, //< Server software must be restarted
RESTART_HARDWARE, //< Physical robot must be rebooted
LAST_RESTART_LEVEL = RESTART_HARDWARE
};
enum {
DEFAULT_DOUBLE_PRECISION = 5, ///< Default double precision, originates from previous saving behavior
TYPE_COUNT = LAST_TYPE + 1, ///< Number of argument types
RESTART_LEVEL_COUNT = LAST_RESTART_LEVEL + 1, ///< Number of restart levels
};
/// Keyword that indicates the start of an ArConfigArg LIST object, for ArFileParser.
static const char *LIST_BEGIN_TAG;
/// Keyword that indicates the end of an ArConfigArg LIST object, for ArFileParser.
static const char *LIST_END_TAG;
/// Resource file keyword that indicates an empty string (cannot write empty for csv).
static const char *NULL_TAG;
/// Resource file keyword that indicates a new entry.
static const char *NEW_RESOURCE_TAG;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Static Methods
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/// Returns a text representation of the given type, suitable for logging.
static const char *toString(Type t);
/// Returns a text representation of the given RestartLevel, suitable for logging.
static const char *toString(RestartLevel r);
/// Given a text representation, returns the appropriate Type.
static Type typeFromString(const char *text);
/// Given a text representation, returns the appropriate RestartLevel.
static RestartLevel restartLevelFromString(const char *text);
/// Returns the section name contained in the given resource arg.
AREXPORT static std::string parseResourceSectionName(ArArgumentBuilder *arg,
const char *logPrefix = "");
/// Returns the param name contained in the given resource arg.
AREXPORT static std::string parseResourceArgName(ArArgumentBuilder *arg,
const char *logPrefix = "");
/// Returns the arg type contained in the given resource arg.
AREXPORT static Type parseResourceType(ArArgumentBuilder *arg,
const char *logPrefix = "");
/// Returns true if the given resource arg is "top-level", i.e. not a list member.
AREXPORT static bool isResourceTopLevel(ArArgumentBuilder *arg,
const char *logPrefix = "");
/// Returns the parent path contained in the resource arg for list members.
AREXPORT static std::list<std::string> parseResourceParentPath(ArArgumentBuilder *arg,
char separator = '|',
const char *logPrefix = "");
/// Returns the description contained in the given resource arg.
AREXPORT static std::string parseResourceDescription(ArArgumentBuilder *arg,
const char *logPrefix = "");
/// Returns the extra explanation contained in the given resource arg.
AREXPORT static std::string parseResourceExtra(ArArgumentBuilder *arg,
const char *logPrefix = "");
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Instance Methods
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/// Default empty contructor
AREXPORT ArConfigArg();
/// Constructor for making an integer argument by pointer (4 bytes)
AREXPORT ArConfigArg(const char * name, int *pointer,
const char * description = "",
int minInt = INT_MIN,
int maxInt = INT_MAX);
/// Constructor for making an int argument thats a short (2 bytes)
AREXPORT ArConfigArg(const char * name, short *pointer,
const char * description = "",
int minInt = SHRT_MIN,
int maxInt = SHRT_MAX);
/// Constructor for making an int argument thats a ushort (2 bytes)
AREXPORT ArConfigArg(const char * name, unsigned short *pointer,
const char * description = "",
int minInt = 0,
int maxInt = USHRT_MAX);
/// Constructor for making an char (1 byte) argument by pointer (treated as int)
AREXPORT ArConfigArg(const char * name, unsigned char *pointer,
const char * description = "",
int minInt = 0,
int maxInt = 255);
/// Constructor for making a double argument by pointer
AREXPORT ArConfigArg(const char * name,
double *pointer,
const char * description = "",
double minDouble = -HUGE_VAL,
double maxDouble = HUGE_VAL,
int precision = DEFAULT_DOUBLE_PRECISION);
/// Constructor for making a boolean argument by pointer
AREXPORT ArConfigArg(const char * name, bool *pointer,
const char * description = "");
/// Constructor for making an argument of a string by pointer (see details)
AREXPORT ArConfigArg(const char *name, char *str,
const char *description,
size_t maxStrLen);
/// Constructor for making an argument of a string by pointer (see details)
AREXPORT ArConfigArg(const char *name, const char *str,
const char *description);
/// Constructor for making an argument of a C++ std::string
AREXPORT ArConfigArg(const char *name, std::string *str, const char *description);
/// Constructor for making an integer argument
AREXPORT ArConfigArg(const char * name, int val,
const char * description = "",
int minInt = INT_MIN,
int maxInt = INT_MAX);
/// Constructor for making a double argument
AREXPORT ArConfigArg(const char * name,
double val,
const char * description = "",
double minDouble = -HUGE_VAL,
double maxDouble = HUGE_VAL,
int precision = DEFAULT_DOUBLE_PRECISION);
/// Constructor for making a boolean argument
AREXPORT ArConfigArg(const char * name, bool val,
const char * description = "");
/// Constructor for making an argument that has functors to handle things
AREXPORT ArConfigArg(const char *name,
ArRetFunctor1<bool, ArArgumentBuilder *> *setFunctor,
ArRetFunctor<const std::list<ArArgumentBuilder *> *> *getFunctor,
const char *description);
/// Constructor for just holding a description (for ArConfig)
AREXPORT ArConfigArg(const char *str, Type type = DESCRIPTION_HOLDER);
/// Constructor for holding an unknown argument (STRING_HOLDER)
AREXPORT ArConfigArg(const char *name, const char *str);
/// Constructs a new named argument of the specified type.
AREXPORT ArConfigArg(Type type,
const char *name,
const char *description);
/// Constructs a new argument of the specified type.
AREXPORT ArConfigArg(Type type);
/// Destructor
AREXPORT virtual ~ArConfigArg();
/// Copy constructor that allows a new name to be assigned
AREXPORT ArConfigArg(const char *argName,
const ArConfigArg & arg);
/// Copy constructor
AREXPORT ArConfigArg(const ArConfigArg & arg);
/// Assignment operator
AREXPORT ArConfigArg &operator=(const ArConfigArg &arg);
/// Copies the given arg to this one, detaching any pointers so they are not shared
AREXPORT void copyAndDetach(const ArConfigArg &arg);
/// Copies the translation data from given arg to this one.
AREXPORT bool copyTranslation(const ArConfigArg &arg);
/// Gets the type of the argument
AREXPORT ArConfigArg::Type getType(void) const;
/// Gets the name of the argument
AREXPORT const char *getName(void) const;
/// Gets the brief description of the argument
AREXPORT const char *getDescription(void) const;
/// Sets the description (normally given in the constructor)
AREXPORT void setDescription(const char *description);
/// For arguments that require more than a brief description, set the extra explanation.
AREXPORT void setExtraExplanation(const char *extraExplanation);
/// Returns the extra explanation, if any, for this argument
AREXPORT const char *getExtraExplanation() const;
/// Sets the argument value, for int arguments
AREXPORT bool setInt(int val,
char *errorBuffer = NULL, size_t errorBufferLen = 0,
bool doNotSet = false);
/// Sets the argument value, for double arguments
AREXPORT bool setDouble(double val,
char *errorBuffer = NULL, size_t errorBufferLen = 0,
bool doNotSet = false);
/// Sets the argument value, for bool arguments
AREXPORT bool setBool(bool val,
char *errorBuffer = NULL, size_t errorBufferLen = 0,
bool doNotSet = false);
/// Sets the argument value for string arguments
AREXPORT bool setString(const char *str,
char *errorBuffer = NULL, size_t errorBufferLen = 0,
bool doNotSet = false);
#ifndef SWIG
/// Sets the argument value for string arguments. The value of @a str is copied to the target string.
AREXPORT bool setString(const std::string &str,
char *errorBuffer = NULL, size_t errorBufferLen = 0,
bool doNotSet = false);
#endif
AREXPORT bool setCppString(const std::string &str,
char *errorBuffer = NULL, size_t errorBufferLen = 0,
bool doNotSet = false);
/// Sets the argument by calling the setFunctor callback
AREXPORT bool setArgWithFunctor(ArArgumentBuilder *argument,
char *errorBuffer = NULL,
size_t errorBufferLen = 0,
bool doNotSet = false);
/// Gets the argument value, for int arguments
AREXPORT int getInt(bool *ok = NULL) const;
/// Gets the minimum int value
AREXPORT int getMinInt(bool *ok = NULL) const;
/// Gets the maximum int value
AREXPORT int getMaxInt(bool *ok = NULL) const;
/// Gets the argument value, for double arguments
AREXPORT double getDouble(bool *ok = NULL) const;
/// Gets the minimum double value
AREXPORT double getMinDouble(bool *ok = NULL) const;
/// Gets the maximum double value
AREXPORT double getMaxDouble(bool *ok = NULL) const;
/// Gets the decimal precision of the double
AREXPORT int getDoublePrecision(bool *ok = NULL) const;
/// Gets the argument value, for bool arguments
AREXPORT bool getBool(bool *ok = NULL) const;
/// Gets the argument value, for string (and string holder) arguments
AREXPORT const char *getString(bool *ok = NULL) const;
/// Gets the argument value, which is a list of argumentbuilders here
AREXPORT const std::list<ArArgumentBuilder *> *getArgsWithFunctor(bool *ok = NULL) const;
AREXPORT std::string getCppString(bool *ok = NULL) const;
AREXPORT const std::string* getCppStringPtr(bool *ok = NULL) const;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Methods for LIST Type
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/// Adds a child arg to this arg. Valid only for LIST type; otherwise returns false.
AREXPORT bool addArg(const ArConfigArg &arg);
/// Returns whether the list contains child args. Valid only for LIST type; otherwise returns false.
AREXPORT bool hasArgs() const;
/// Returns the number of child args. Valid only for LIST type; otherwise returns 0.
AREXPORT size_t getArgCount() const;
// KMC 7/9/12 Right now, the returned args will not have the parent set to this arg.
// I suspect that this may present an implementation issue later but am not sure.
// Perhaps the addition of an iterator would suffice.
//
/// Returns a list of all child args in this arg. Valid only for LIST type; otherwise returns an empty list.
AREXPORT std::list<ArConfigArg> getArgs(bool *ok = NULL) const;
/// Returns the child arg at the specified index (between 0 and getArgCount()).
AREXPORT const ArConfigArg *getArg(size_t index) const;
/// Returns the child arg at the specified index (between 0 and getArgCount()).
AREXPORT ArConfigArg *getArg(size_t index);
/// Finds the specified child arg. Valid only for LIST type; otherwise returns NULL.
AREXPORT const ArConfigArg *findArg(const char *childParamName) const;
/// Finds the specified child arg. Valid only for LIST type; otherwise returns NULL.
AREXPORT ArConfigArg *findArg(const char *childParamName);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Miscellaneous Attributes
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/// Gets the priority (only used by ArConfig)
AREXPORT ArPriority::Priority getConfigPriority(void) const;
/// Sets the priority (only used by ArConfig)
AREXPORT void setConfigPriority(ArPriority::Priority priority);
/// Returns the display hint for this arg, or NULL if none is defined.
AREXPORT const char *getDisplayHint() const;
/// Sets the display hint for this arg.
AREXPORT void setDisplayHint(const char *hintText);
/// Gets the restart level of this parameter (only used by ArConfig)
AREXPORT RestartLevel getRestartLevel() const;
/// Sets the restart level of this parameter (only used by ArConfig)
AREXPORT void setRestartLevel(RestartLevel level);
/// Gets if notifications of changes are supressed (for the central
/// server config)
AREXPORT bool getSupressChanges(void) const;
/// Sets if notifications of changes are supressed (for the central
/// server config)
AREXPORT void setSupressChanges(bool supressChanges);
/// Returns a pointer to the immediate parent arg. If this is not a child ArConfigArg, then returns NULL.
AREXPORT ArConfigArg *getParentArg() const;
/// If getParentArg() is not null, then returns the path to the top level, as a single string
AREXPORT std::string getParentPathName(char separator = '|') const;
/// Given a parent path, as a single string, splits it in a format useable by ArConfigSection findParam
AREXPORT static std::list<std::string> splitParentPathName(const char *parentPathName,
char separator = '|');
/// Replaces spaces in the name with underscores
AREXPORT void replaceSpacesInName(void);
/// Returns whether the arg has a minimum value, currently applicable to INTs and DOUBLEs
AREXPORT bool hasMinBound() const;
/// Returns whether the arg has a maximum value, currently applicable to INTs and DOUBLEs
AREXPORT bool hasMaxBound() const;
/// Sets whether to ignore bounds or not (default is to not to)
AREXPORT void setIgnoreBounds(bool ignoreBounds = false);
/// Returns true if this arg points to a member of another object, false if arg is self-contained.
AREXPORT bool hasExternalDataReference() const;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Generic (Type-Independent) Methods
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/// Adds given parserCB handler for the appropriate keyword(s) to the given file parser.
AREXPORT bool addToFileParser(ArFileParser *parser,
ArRetFunctor3C<bool,
ArConfig,
ArArgumentBuilder *,
char *,
size_t> *parserCB,
const char *logPrefix = "",
bool isQuiet = false) const;
/// Sets the value of this arg to the data described in the given ArArgumentBuilder
AREXPORT bool parseArgument(ArArgumentBuilder *arg,
char *errorBuffer,
size_t errorBufferLen,
const char *logPrefix = "",
bool isQuiet = false,
bool *changed = NULL);
/// Writes this arg to the given file, in a format suitable for reading by parseArgument.
AREXPORT bool writeArguments(FILE *file,
char *lineBuf,
int lineBufSize,
int startCommentColumn,
bool isWriteExtra = false,
const char *logPrefix = "",
int indentLevel = 0) const;
/// Writes the name of this arg to the given buffer, indenting as specified.
AREXPORT bool writeName(char *lineBuf,
int lineBufSize,
int indentLevel) const;
/// Writes the min/max values of this arg to the given buffer, as applicable.
AREXPORT bool writeBounds(char *line,
size_t lineLen,
const char *logPrefix = "") const;
/// Logs the type, name, and value of this argument
AREXPORT void log(bool verbose = false,
int indentCount = 1,
const char *logPrefix = "") const;
/// Checks only the name, type, and value attributes and returns whether they are equal.
AREXPORT bool isValueEqual(const ArConfigArg &other) const;
/// If the given source is of the same type, copies its value to this arg
/**
* Note that this method currently only works for the primitive arg
* types (i.e. int, bool, etc.). It doesn't copy functors or description
* holders.
*
* @param source the ArConfigArg whose value is to be copied to this arg
* @param isVerifyArgNames a bool set to true if the argument value should
* be set only if the given source has the same name as this argument;
* the default value is false
* @return bool true if the value was copied; false if the source was of a
* different (or non-copyable) type
**/
AREXPORT bool setValue(const ArConfigArg &source,
bool isVerifyArgNames = false);
/// Gets whether this value has been set since it was last cleared or not
bool isValueSet(void) { return myValueSet; }
/// Tells the configArg that the value hasn't been set
void clearValueSet(void) { myValueSet = false; }
/// For special arg types (such as LIST), sets the flag to indicate the value was set.
void setValueSet(void) { myValueSet = true; }
/// Returns whether the arg has been translated by a resource file.
bool isTranslated() const;
/// Sets whether the arg has been translated by a resource file.
void setTranslated(bool b);
enum ResourceIndices {
RESOURCE_INDEX_OF_SECTION_NAME = 0,
RESOURCE_INDEX_OF_ARG_NAME = 1,
RESOURCE_INDEX_OF_TYPE = 2,
RESOURCE_INDEX_OF_PRIORITY = 3,
RESOURCE_INDEX_OF_RESTART_LEVEL = 4,
RESOURCE_INDEX_OF_PARENT_PATH = 5,
RESOURCE_INDEX_OF_DESCRIPTION = 6,
RESOURCE_INDEX_OF_EXTRA = 7,
RESOURCE_INDEX_OF_DISPLAY = 8, // not yet supported
RESOURCE_INDEX_OF_NEW = 9
};
enum {
MAX_RESOURCE_ARG_TEXT_LENGTH = 1024
};
/// Sets the value of this arg to the resource data described in the given ArArgumentBuilder
AREXPORT bool parseResource(ArArgumentBuilder *arg,
char *errorBuffer,
size_t errorBufferLen,
const char *logPrefix = "",
bool isQuiet = false);
/// Parses the text obtained from the resource arg, strips surrounding quotes, blanks, and funny chars.
AREXPORT static bool parseResourceArgText(const char *argText,
char *bufOut,
size_t bufLen);
/// Writes this arg to the given file, in a format suitable for reading by parseResource.
AREXPORT bool writeResource(FILE *file,
char *lineBuf,
int lineBufSize,
char separatorChar,
const char *sectionName,
const char *logPrefix = "") const;
/// Writes column labels and edit info to the given resource file, returns number of lines written
AREXPORT static int writeResourceHeader(FILE *file,
char *lineBuf,
int lineBufSize,
char separatorChar,
const char *sectionTitle,
const char *logPrefix = "");
/// Writes the section description to the resource file.
AREXPORT static int writeResourceSectionHeader(FILE *file,
char *lineBuf,
int lineBufSize,
char separatorChar,
const char *sectionName,
const char *sectionDesc,
const char *sectionExtra,
const char *sectionDisplayName,
bool isTranslated,
const char *logPrefix = "");
protected:
// Giving ArConfig access to the write method
friend class ArConfig;
/// Writes the given comment to the specified file, spanning multiple lines as necessary.
AREXPORT static bool writeMultiLineComment(const char *comment,
FILE *file,
char *lineBuf,
int lineBufSize,
const char *startComment);
private:
enum IntType {
INT_NOT, ///< Not an int
INT_INT, ///< An int (4 bytes)
INT_SHORT, ///< A short (2 bytes)
INT_UNSIGNED_SHORT, ///< An unsigned short (2 bytes)
INT_UNSIGNED_CHAR ///< An unsigned char (1 byte)
};
/// Internal helper function
void clear(bool initial,
Type type = INVALID,
IntType intType = INT_NOT,
bool isDelete = true);
/// Copies the given arg to this one, optionally detaching any internal pointer
void copy(const ArConfigArg &arg, bool isDetach = false);
void set(ArConfigArg::Type type,
const char *name,
const char *description,
IntType intType = INT_NOT);
/// Sets the parent pointer of this arg.
void setParent(ArConfigArg *parentArg);
/// Whether the arg type is LIST or LIST_HOLDER
bool isListType() const;
// KMC 7/11/12 Changed from protected to private so future changes are less
// of a concern
// protected:
private:
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/// Data applicable to INT args
struct ArConfigIntData {
// int data
ArConfigArg::IntType myIntType;
// If unions need to be avoided for some reason, then this can simply
// be turned into a struct.
//
// begin union (based on myIntType)
union {
int *myIntPointer;
short *myIntShortPointer;
unsigned short *myIntUnsignedShortPointer;
unsigned char *myIntUnsignedCharPointer;
};
// end union (based on myIntType)
int myMinInt;
int myMaxInt;
}; // end struct ArConfigIntData
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/// Data applicable to DOUBLE args
struct ArConfigDoubleData {
double *myDoublePointer;
double myMinDouble;
double myMaxDouble;
int myPrecision;
}; // end struct ArConfigDoubleData
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/// Data applicable to BOOL args
struct ArConfigBoolData {
bool *myBoolPointer;
}; // end struct ArConfigBoolData
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/// Data applicable to STRING and STRING_HOLDER args
struct ArConfigStringData {
// string data
char *myStringPointer;
size_t myMaxStrLen;
// KMC own string change
// Not seeing the functional difference between this and myOwnPointedTo
// (which was previously applied to all but strings)
// bool myUsingOwnedString;
std::string *myString; ///< Used if myOwnedString is true. (Union member cannot have a copy constructor so using a pointer)
}; // end struct ArConfigStringData
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/// Data applicable to CPPSTRING
struct ArConfigCppStringData {
std::string *myCppStringPtr;
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/// Data applicable to LIST args
struct ArConfigListData {
std::list<ArConfigArg> *myChildArgList;
}; // end struct ArConfigListData
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/// Data applicable to FUNCTOR args
struct ArConfigFunctorData {
ArRetFunctor1<bool, ArArgumentBuilder *> *mySetFunctor;
ArRetFunctor<const std::list<ArArgumentBuilder *> *> *myGetFunctor;
}; // end struct ArConfigFunctorData
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//
// If unions need to be avoided for some reason, then this can simply
// be turned into a struct.
//
/// Data that varies according to type of arg
union ArConfigArgData { // begin union (based on myType)
ArConfigIntData myIntData;
ArConfigDoubleData myDoubleData;
ArConfigBoolData myBoolData;
ArConfigStringData myStringData;
ArConfigListData myListData;
ArConfigFunctorData myFunctorData;
ArConfigCppStringData myCppStringData;
}; // end union (based on myType)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/// Number of spaces to indent each level of list contents
static int ourIndentSpaceCount;
static std::map<std::string, Type> *ourTextToTypeMap;
static std::map<std::string, RestartLevel> *ourTextToRestartLevelMap;
/// Type of this arg
ArConfigArg::Type myType;
/// Name of this arg (may be empty for SEPARATOR args)
std::string myName;
/// Brief description of this arg
std::string myDescription;
/// An optional extra explanation for args that need clarification
std::string myExtraExplanation;
/// Name to be displayed in client applications. (Not yet supported.)
std::string myDisplayName;
ArConfigArgData myData;
/// Priority of this arg
ArPriority::Priority myConfigPriority;
/// Optional display hint used by clients
std::string myDisplayHint;
/// Indicates whether modifying the arg will result in a system restart
RestartLevel myRestartLevel;
/// Supressses change notification (for central server config params that should cause a restart on a robot, but not on the central server)
bool mySupressChanges;
/// Pointer to the parent arg, or NULL if this arg is not a member of a LIST
ArConfigArg *myParentArg;
/// Whether this arg "owns" its data, i.e. does not point to a member of another object
bool myOwnPointedTo : 1;
/// Whether this arg has been set to its initial value
bool myValueSet : 1;
/// Whether any min/max bounds requirements on this arg should be ignored
bool myIgnoreBounds : 1;
/// Whether this arg has been translated by a resource file
bool myIsTranslated : 1;
}; // end class ArConfigArg
#endif // ARCONFIGARG_H
|