/usr/include/ThePEG/Interface/Parameter.h is in libthepeg-dev 1.8.0-3build1.
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 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 | // -*- C++ -*-
//
// Parameter.h is a part of ThePEG - Toolkit for HEP Event Generation
// Copyright (C) 1999-2011 Leif Lonnblad
//
// ThePEG is licenced under version 2 of the GPL, see COPYING for details.
// Please respect the MCnet academic guidelines, see GUIDELINES for details.
//
#ifndef ThePEG_Parameter_H
#define ThePEG_Parameter_H
// This is the declaration of the Parameter, ParameterTBase and
// ParameterBase classes.
#include "ThePEG/Config/ThePEG.h"
#include "InterfaceBase.h"
#include "Parameter.xh"
#include "Parameter.fh"
#include "ThePEG/Utilities/StringUtils.h"
#include <limits>
namespace ThePEG {
/// Helper functions for putUnit()
namespace {
template <typename T>
/**
* Helper functions for putUnit
*/
inline void putUnitImpl(ostream & os, T v, T u, DimensionT) {
os << v/u;
}
template <typename T>
/**
* Helper functions for putUnit
*/
inline void putUnitImpl(ostream & os, T v, T u, StandardT) {
if ( u > T() )
os << v/u;
else
os << v;
}
}
/**
* The Parameter and its base classes ParameterTBase and ParameterBase
* defines an interface to a class derived from the InterfacedBase,
* through which simple member variables can be
* manuipulated. Parameter is templated on the type of the member
* variable and the type of the InterfacedBase class, and is derived
* from the InterfaceBase class via ParameterTBase (which is templated
* only on the type of the member variable) and ParameterBase.
*
* For each InterfacedBase class exactly one static Parameter object
* should created for each member variable which should be
* interfaced. This object will automatically register itself with the
* BaseRepository class.
*
* @see InterfacedBase
* @see InterfaceBase
*
*/
class ParameterBase: public InterfaceBase {
public:
/**
* Standard constructor.
*
* @param newName the name of the interface, may only contain
* letters [a-zA-z0-9_].
*
* @param newDescription a brief description of the interface.
*
* @param newClassName the name of the corresponding class.
*
* @param newTypeInfo the type_info object of the corresponding
* class.
*
* @param depSafe set to true if calls to this interface for one
* object does not influence other objects.
*
* @param readonly if this is set true the interface will not be
* able to manipulate objects of the corresponding class, but will
* still be able to access information.
*
* @param limits determines if the values of the parameters are
* limited from above and/or below. The possible values are given by
* Interface::Limits.
*/
ParameterBase(string newName, string newDescription,
string newClassName,
const type_info & newTypeInfo, bool depSafe,
bool readonly, int limits)
: InterfaceBase(newName, newDescription,
newClassName, newTypeInfo, depSafe,
readonly), limit(limits) {}
/**
* The destructor.
*/
virtual ~ParameterBase();
/**
* The general interface method overriding the one in
* InterfaceBase. For this class, \a action can be any of "set",
* "get", "min", "max", "def" and "setdef" and \a argument should be
* a something which can be read into a variable through a
* stringstream with the standard '>>' operator.
*/
virtual string exec(InterfacedBase & ib, string action,
string arguments) const;
/**
* Return a complete description of this parameter.
*/
virtual string fullDescription(const InterfacedBase & ib) const;
/**
* Set the member variable of \a ib to \a val.
*/
virtual void set(InterfacedBase & ib, string) const
= 0;
/**
* Return the minimum value allowed for the member variable of \a ib.
*/
virtual string minimum(const InterfacedBase & ib) const
= 0;
/**
* Return the maximum value allowed for the member variable of \a ib.
*/
virtual string maximum(const InterfacedBase & ib) const
= 0;
/**
* Return the value of the member variable of \a ib.
*/
virtual string get(const InterfacedBase & ib) const
= 0;
/**
* Return the default value for the member variable of \a ib.
*/
virtual string def(const InterfacedBase & ib) const
= 0;
/**
* Set the member variable of \a ib to its default value.
*/
virtual void setDef(InterfacedBase & ib) const
= 0;
/**
* True if there the variable is limited from above and below.
*/
bool limited() const { return limit != Interface::nolimits; }
/**
* True if there the variable is limited from abovew.
*/
bool upperLimit() const {
return limit == Interface::limited || limit == Interface::upperlim;
}
/**
* True if there the variable is limited from below.
*/
bool lowerLimit() const {
return limit == Interface::limited || limit == Interface::lowerlim;
}
/**
* Set flag indicating that there are limits associated with the
* variable.
*/
void setLimited() { limit = Interface::limited; }
/**
* Set flag indicating that there are no limits associated with the
* variable.
*/
void setUnlimited() { limit = Interface::nolimits; }
private:
/**
* Determines if the values of the parameters are
* limited from above and/or below. The possible values are given by
* Interface::Limits.
*/
int limit;
};
/**
* The Parameter and its base classes ParameterTBase and ParameterBase
* defines an interface to a class derived from the InterfacedBase,
* through which simple member variables can be
* manuipulated. Parameter is templated on the type of the member
* variable and the type of the InterfacedBase class, and is derived
* from the InterfaceBase class via ParameterTBase (which is templated
* only on the type of the member variable) and ParameterBase.
*
* For each InterfacedBase class exactly one static Parameter object
* should created for each member variable which should be
* interfaced. This object will automatically register itself with the
* BaseRepository class.
*
* @see InterfacedBase
* @see InterfaceBase
*
*/
template <typename Type>
class ParameterTBase: public ParameterBase {
public:
/**
* Standard constructor.
*
* @param newName the name of the interface, may only contain
* letters [a-zA-z0-9_].
*
* @param newDescription a brief description of the interface.
*
* @param newClassName the name of the corresponding class.
*
* @param newTypeInfo the type_info object of the corresponding
* class.
*
* @param newUnit the unit assumed when a number is read or written
* to a stream.
*
* @param depSafe set to true if calls to this interface for one
* object does not influence other objects.
*
* @param readonly if this is set true the interface will not be
* able to manipulate objects of the corresponding class, but will
* still be able to access information.
*
* @param limits determines if the values of the parameters are
* limited from above and/or below. The possible values are given by
* Interface::Limits.
*/
ParameterTBase(string newName, string newDescription,
string newClassName,
const type_info & newTypeInfo, Type newUnit,
bool depSafe, bool readonly, int limits)
: ParameterBase(newName, newDescription,
newClassName, newTypeInfo, depSafe,
readonly, limits), theUnit(newUnit) {}
/**
* Destructor.
*/
virtual ~ParameterTBase() {}
/**
* Return a code for the type of this parameter.
*/
virtual string type() const;
private:
/// Implementation of set() for standard types.
void setImpl (InterfacedBase & i,
string newValue, StandardT)
const;
/// Implementation of set() for dimensioned types.
void setImpl (InterfacedBase & i,
string newValue, DimensionT)
const;
public:
/**
* Set the member variables of \a ib to \a val. Uses a stringstream
* to read the \a val into a Type object and then calls
* tset(InterfacedBase &, Type).
*/
virtual void set(InterfacedBase & ib, string newValue)
const;
/**
* Set the member variables of \a ib to \a val.
*/
virtual void tset(InterfacedBase & ib, Type) const
= 0;
/**
* Return the value of the member variable of \a ib. Calls
* tget(const InterfacedBase &) and converts the returned value with
* an ostringstream.
*/
virtual string get(const InterfacedBase & ib) const
;
/**
* Return the value of the member variable of \a ib.
*/
virtual Type tget(const InterfacedBase & ib) const
= 0;
/**
* Return the minimum value allowed for the member variable of \a
* ib. Calls tmimimum(const InterfacedBase &) and converts the
* returned value with an ostringstream.
*/
virtual string minimum(const InterfacedBase & ib) const
;
/**
* Return the minimum value allowed for the member variable of \a
* ib.
*/
virtual Type tminimum(const InterfacedBase & ib) const
= 0;
/**
* Return the maximum value allowed for the member variable of \a
* ib. Calls tmaximum(const InterfacedBase &) and converts the
* returned value with an ostringstream.
*/
virtual string maximum(const InterfacedBase & ib) const
;
/**
* Return the maximum value allowed for the member variable of
* \a ib.
*/
virtual Type tmaximum(const InterfacedBase & ib) const
= 0;
/**
* Return the default value for the member variables of \a ib. Calls
* tdef(const InterfacedBase &) and converts the returned value with
* an ostringstream.
*/
virtual string def(const InterfacedBase & ib) const
;
/**
* Return the default value for the member variables of \a ib.
*/
virtual Type tdef(const InterfacedBase &ib) const
= 0;
/**
* set the member variable of \a ib to its default value.
*/
virtual void setDef(InterfacedBase & ib) const {
tset(ib, tdef(ib));
}
/**
* Get the unit which an Type object is divided (multiplied) by when
* written to (read from) a stream via a double. If unit() is zero,
* the Type object is written/read directly.
*/
Type unit() const { return theUnit; }
/**
* Set the unit which an Type object is divided (multiplied) by when
* written to (read from) a stream via a double. If unit() is zero,
* the Type object is written/read directly.
*/
void unit(Type u) { theUnit = u; }
/**
* Return a string describing the type of interface to be included
* in the Doxygen documentation.
*/
virtual string doxygenType() const;
protected:
/**
* Write a number to a stream with the unit specified with unit().
*/
void putUnit(ostream & os, Type val) const {
putUnitImpl(os, val, unit(), typename TypeTraits<Type>::DimType());
}
private:
/**
* The unit which an Type object is divided (multiplied) by
* when written to (read from) a stream via a double. If unit() is
* zero, the Type object is written/read directly.
*/
Type theUnit;
};
/**
* The Parameter and its base classes ParameterTBase and ParameterBase
* defines an interface to a class derived from the InterfacedBase,
* through which simple member variables can be
* manuipulated. Parameter is templated on the type of the member
* variable and the type of the InterfacedBase class, and is derived
* from the InterfaceBase class via ParameterTBase (which is templated
* only on the type of the member variable) and ParameterBase.
*
* For each InterfacedBase class exactly one static Parameter object
* should created for each member variable which should be
* interfaced. This object will automatically register itself with the
* BaseRepository class.
*
* @see InterfacedBase
* @see InterfaceBase
*
*/
template <typename T, typename Type>
class Parameter: public ParameterTBase<Type> {
public:
/**
* The declaration of member functions which can be used by this
* Switch interface for the 'set' action.
*/
typedef void (T::*SetFn)(Type);
/**
* The declaration of member functions which can be used by this
* Switch interface for the 'get', 'def', 'min' and 'max' actions.
*/
typedef Type (T::*GetFn)() const;
/**
* Declaration of a direct pointer to the member variable.
*/
typedef Type T::* Member;
public:
/**
* Standard constructor.
*
* @param newName the name of the interface, may only contain
* letters [a-zA-z0-9_].
*
* @param newDescription a brief description of the interface.
*
* @param newMember a pointer to the member variable. May be null if
* corresponding set/get functions are provided.
*
* @param newDef the default value for the member variable.
*
* @param newMin the minimum value for the member variable.
*
* @param newMax the maximum value for the member variable.
*
* @param depSafe set to true if calls to this interface for one
* object does not influence other objects.
*
* @param readonly if this is set true the interface will not be
* able to manipulate objects of the corresponding class, but will
* still be able to access information.
*
* @param limits determines if the values of the parameters are
* limited from above and below.
*
* @param newSetFn optional pointer to the member function for the
* 'set' action.
*
* @param newGetFn optional pointer to the member function for the
* 'get' action.
*
* @param newMinFn optional pointer to the member function for the
* 'min' action.
*
* @param newMaxFn optional pointer to the member function for the
* 'max' action.
*
* @param newDefFn optional pointer to the member function for the
* 'def' action.
*/
Parameter(string newName, string newDescription,
Member newMember, Type newDef, Type newMin,
Type newMax, bool depSafe = false, bool readonly = false,
bool limits = true, SetFn newSetFn = 0,
GetFn newGetFn = 0, GetFn newMinFn = 0,
GetFn newMaxFn = 0, GetFn newDefFn = 0)
: ParameterTBase<Type>(newName, newDescription, ClassTraits<T>::className(),
typeid(T), Type(), depSafe, readonly, limits),
theMember(newMember), theDef(newDef), theMin(newMin), theMax(newMax),
theSetFn(newSetFn), theGetFn(newGetFn), theDefFn(newDefFn),
theMinFn(newMinFn), theMaxFn(newMaxFn) {}
/**
* Standard constructor.
*
* @param newName the name of the interface, may only contain
* letters [a-zA-z0-9_].
*
* @param newDescription a brief description of the interface.
*
* @param newMember a pointer to the member variable. May be null if
* corresponding set/get functions are provided.
*
* @param newUnit the unit assumed when a number is read or written
* to a stream.
*
* @param newDef the default value for the member variable.
*
* @param newMin the minimum value for the member variable.
*
* @param newMax the maximum value for the member variable.
*
* @param depSafe set to true if calls to this interface for one
* object does not influence other objects.
*
* @param readonly if this is set true the interface will not be
* able to manipulate objects of the corresponding class, but will
* still be able to access information.
*
* @param limits determines if the values of the parameters are
* limited from above and below.
*
* @param newSetFn optional pointer to the member function for the
* 'set' action.
*
* @param newGetFn optional pointer to the member function for the
* 'get' action.
*
* @param newMinFn optional pointer to the member function for the
* 'min' action.
*
* @param newMaxFn optional pointer to the member function for the
* 'max' action.
*
* @param newDefFn optional pointer to the member function for the
* 'def' action.
*/
Parameter(string newName, string newDescription,
Member newMember, Type newUnit, Type newDef, Type newMin,
Type newMax, bool depSafe = false, bool readonly = false,
bool limits = true, SetFn newSetFn = 0,
GetFn newGetFn = 0, GetFn newMinFn = 0,
GetFn newMaxFn = 0, GetFn newDefFn = 0)
: ParameterTBase<Type>(newName, newDescription, ClassTraits<T>::className(),
typeid(T), newUnit, depSafe, readonly, limits),
theMember(newMember), theDef(newDef), theMin(newMin), theMax(newMax),
theSetFn(newSetFn), theGetFn(newGetFn), theDefFn(newDefFn),
theMinFn(newMinFn), theMaxFn(newMaxFn) {}
/**
* Standard constructor.
*
* @param newName the name of the interface, may only contain
* letters [a-zA-z0-9_].
*
* @param newDescription a brief description of the interface.
*
* @param newMember a pointer to the member variable. May be null if
* corresponding set/get functions are provided.
*
* @param newDef the default value for the member variable.
*
* @param newMin the minimum value for the member variable.
*
* @param newMax the maximum value for the member variable.
*
* @param depSafe set to true if calls to this interface for one
* object does not influence other objects.
*
* @param readonly if this is set true the interface will not be
* able to manipulate objects of the corresponding class, but will
* still be able to access information.
*
* @param limits determines if the values of the parameters are
* limited from above and/or below. The possible values are given by
* Interface::Limits.
*
* @param newSetFn optional pointer to the member function for the
* 'set' action.
*
* @param newGetFn optional pointer to the member function for the
* 'get' action.
*
* @param newMinFn optional pointer to the member function for the
* 'min' action.
*
* @param newMaxFn optional pointer to the member function for the
* 'max' action.
*
* @param newDefFn optional pointer to the member function for the
* 'def' action.
*/
Parameter(string newName, string newDescription,
Member newMember, Type newDef, Type newMin,
Type newMax, bool depSafe = false, bool readonly = false,
int limits = Interface::limited, SetFn newSetFn = 0,
GetFn newGetFn = 0, GetFn newMinFn = 0,
GetFn newMaxFn = 0, GetFn newDefFn = 0)
: ParameterTBase<Type>(newName, newDescription, ClassTraits<T>::className(),
typeid(T), Type(), depSafe, readonly, limits),
theMember(newMember), theDef(newDef), theMin(newMin), theMax(newMax),
theSetFn(newSetFn), theGetFn(newGetFn), theDefFn(newDefFn),
theMinFn(newMinFn), theMaxFn(newMaxFn) {}
/**
* Standard constructor.
*
* @param newName the name of the interface, may only contain
* letters [a-zA-z0-9_].
*
* @param newDescription a brief description of the interface.
*
* @param newMember a pointer to the member variable. May be null if
* corresponding set/get functions are provided.
*
* @param newUnit the unit assumed when a number is read or written
* to a stream.
*
* @param newDef the default value for the member variable.
*
* @param newMin the minimum value for the member variable.
*
* @param newMax the maximum value for the member variable.
*
* @param depSafe set to true if calls to this interface for one
* object does not influence other objects.
*
* @param readonly if this is set true the interface will not be
* able to manipulate objects of the corresponding class, but will
* still be able to access information.
*
* @param limits determines if the values of the parameters are
* limited from above and/or below. The possible values are given by
* Interface::Limits.
*
* @param newSetFn optional pointer to the member function for the
* 'set' action.
*
* @param newGetFn optional pointer to the member function for the
* 'get' action.
*
* @param newMinFn optional pointer to the member function for the
* 'min' action.
*
* @param newMaxFn optional pointer to the member function for the
* 'max' action.
*
* @param newDefFn optional pointer to the member function for the
* 'def' action.
*/
Parameter(string newName, string newDescription,
Member newMember, Type newUnit, Type newDef, Type newMin,
Type newMax, bool depSafe = false, bool readonly = false,
int limits = Interface::limited, SetFn newSetFn = 0,
GetFn newGetFn = 0, GetFn newMinFn = 0,
GetFn newMaxFn = 0, GetFn newDefFn = 0)
: ParameterTBase<Type>(newName, newDescription, ClassTraits<T>::className(),
typeid(T), newUnit, depSafe, readonly, limits),
theMember(newMember), theDef(newDef), theMin(newMin), theMax(newMax),
theSetFn(newSetFn), theGetFn(newGetFn), theDefFn(newDefFn),
theMinFn(newMinFn), theMaxFn(newMaxFn) {}
/**
* Default dtor.
*/
virtual ~Parameter() {}
/**
* Set the member variable of \a ib to \a val.
*/
virtual void tset(InterfacedBase & ib, Type val)
const;
/**
* Return the value of the member variable of ib.
*/
virtual Type tget(const InterfacedBase & ib) const;
/**
* Return the minimum value allowed for the member variable of \a ib.
*/
virtual Type tminimum(const InterfacedBase & ib) const
;
/**
* Return the miaximum value allowed for the member variable of \a ib.
*/
virtual Type tmaximum(const InterfacedBase & ib) const
;
/**
* Return the default value for the member variable of \a ib.
*/
virtual Type tdef(const InterfacedBase & ib) const
;
/**
* Give a pointer to a member function to be used by tset().
*/
void setSetFunction(SetFn sf) { theSetFn = sf; }
/**
* Give a pointer to a member function to be used by tget().
*/
void setGetFunction(GetFn gf) { theGetFn = gf; }
/**
* Give a pointer to a member function to be used by tdef().
*/
void setDefaultFunction(GetFn df) { theDefFn = df; }
/**
* Give a pointer to a member function to be used by tminimum().
*/
void setMinFunction(GetFn mf) { theMinFn = mf; }
/**
* Give a pointer to a member function to be used by tmaximum().
*/
void setMaxFunction(GetFn mf) { theMaxFn = mf; }
/**
* Print a description to be included in the Doxygen documentation
* to the given \a stream.
*/
virtual void doxygenDescription(ostream & stream) const;
private:
/**
* The pointer to the member variable.
*/
Member theMember;
/**
* Default value to be used if no corresponding member function
* pointer is given.
*/
Type theDef;
/**
* Minimum value to be used if no corresponding member function
* pointer is given.
*/
Type theMin;
/**
* Maximum value to be used if no corresponding member function
* pointer is given.
*/
Type theMax;
/**
* A pointer to a member function to be used by tset().
*/
SetFn theSetFn;
/**
* Pointer to member function to be used by tget().
*/
GetFn theGetFn;
/**
* Pointer to member function to be used by tdef().
*/
GetFn theDefFn;
/**
* Pointer to member function to be used by tminimum().
*/
GetFn theMinFn;
/**
* Pointer to member function to be used by tmaximum().
*/
GetFn theMaxFn;
};
/**
* This is a specialization of ParameterTBase for the string case.
*
* @see ParameterTBase
*
*/
template <>
class ParameterTBase<string>: public ParameterBase {
public:
/**
* Enumerated variables to determine of a string parameter
* corresponds to a file or a directory.
*/
enum FileType {
NoFile, /**< Neither file nor directory. */
File, /**< The parameter corresponds to a file. */
Directory /**< The parameter corresponds to a directory. */
};
public:
/**
* Standard constructor.
*
* @param newName the name of the interface, may only contain
* letters [a-zA-z0-9_].
*
* @param newDescription a brief description of the interface.
*
* @param newClassName the name of the corresponding class.
*
* @param newTypeInfo the type_info object of the corresponding
* class.
*
* @param depSafe set to true if calls to this interface for one
* object does not influence other objects.
*
* @param readonly if this is set true the interface will not be
* able to manipulate objects of the corresponding class, but will
* still be able to access information.
*/
ParameterTBase(string newName, string newDescription,
string newClassName,
const type_info & newTypeInfo,
bool depSafe, bool readonly)
: ParameterBase(newName, newDescription,
newClassName, newTypeInfo, depSafe,
readonly, false), isFileType(NoFile) {
hasDefault = false;
}
/**
* Destructor.
*/
virtual ~ParameterTBase() {}
/**
* Return a code for the type of this parameter.
*/
virtual string type() const {
switch ( file() ) {
case File: return "PF";
case Directory: return "PD";
default: return "Ps";
}
}
/**
* Indicate that this parameter corresponds to a file.
*/
void fileType() { file(File); }
/**
* Indicate that this parameter corresponds to a directory.
*/
void directoryType() { file(Directory); }
/**
* Indicate if this parameter corresponds to a file or directory.
*/
void file(FileType t) { isFileType = t; }
/**
* See if this parameter corresponds to a file or directory.
*/
FileType file() const { return isFileType; }
/**
* Set the member variables of \a ib to \a val. Uses a stringstream
* to read the \a val into a Type object and then calls
* tset(InterfacedBase &, Type).
*/
virtual void set(InterfacedBase & ib, string newValue)
const {
tset(ib, StringUtils::stripws(newValue));
}
/**
* Set the member variables of \a ib to \a val.
*/
virtual void tset(InterfacedBase & ib, string) const
= 0;
/**
* Return the value of the member variable of \a ib. Calls
* tget(const InterfacedBase &) and converts the returned value with
* an ostringstream.
*/
virtual string get(const InterfacedBase & ib) const
{
return tget(ib);
}
/**
* Return the value of the member variable of \a ib.
*/
virtual string tget(const InterfacedBase & ib) const
= 0;
/**
* Return the minimum value allowed for the member variable of \a
* ib. Not relevant for strings. Returns the empty string.
*/
virtual string minimum(const InterfacedBase &) const {
return "";
}
/**
* Return the maximum value allowed for the member variable of \a
* ib. Not relevant for strings. Returns the empty string.
*/
virtual string maximum(const InterfacedBase &) const {
return "";
}
/**
* Return the default value for the member variables of \a ib. Calls
* tdef(const InterfacedBase &) and converts the returned value with
* an ostringstream.
*/
virtual string def(const InterfacedBase & ib) const
{
return tdef(ib);
}
/**
* Return the default value for the member variables of \a ib.
*/
virtual string tdef(const InterfacedBase &ib) const
= 0;
/**
* set the member variable of \a ib to its default value.
*/
virtual void setDef(InterfacedBase & i) const {
tset(i, tdef(i));
}
/**
* Return a string describing the type of interface to be included
* in the Doxygen documentation.
*/
virtual string doxygenType() const { return "Character string parameter"; }
private:
/**
* Indicates if this parameter corresponds to a file or directory.
*/
FileType isFileType;
};
/**
* This is a partial specialization of Parameter for the string case.
*
* @see Parameter
*
*/
template <typename T>
class Parameter<T,string>: public ParameterTBase<string> {
public:
/**
* The declaration of member functions which can be used by this
* Switch interface for the 'set' action.
*/
typedef void (T::*SetFn)(string);
/**
* The declaration of member functions which can be used by this
* Switch interface for the 'get', 'def', 'min' and 'max' actions.
*/
typedef string (T::*GetFn)() const;
/**
* Declaration of a direct pointer to the member variable.
*/
typedef string T::* Member;
public:
/**
* Standard constructor.
*
* @param newName the name of the interface, may only contain
* letters [a-zA-z0-9_].
*
* @param newDescription a brief description of the interface.
*
* @param newMember a pointer to the member variable. May be null if
* corresponding set/get functions are provided.
*
* @param newDef the default value for the member variable.
*
* @param depSafe set to true if calls to this interface for one
* object does not influence other objects.
*
* @param readonly if this is set true the interface will not be
* able to manipulate objects of the corresponding class, but will
* still be able to access information.
*
* @param newSetFn optional pointer to the member function for the
* 'set' action.
*
* @param newGetFn optional pointer to the member function for the
* 'get' action.
*
* @param newDefFn optional pointer to the member function for the
* 'def' action.
*/
Parameter(string newName, string newDescription,
Member newMember, string newDef,
bool depSafe = false, bool readonly = false,
SetFn newSetFn = 0, GetFn newGetFn = 0, GetFn newDefFn = 0)
: ParameterTBase<string>(newName, newDescription,
ClassTraits<T>::className(),
typeid(T), depSafe, readonly),
theMember(newMember), theDef(newDef),
theSetFn(newSetFn), theGetFn(newGetFn), theDefFn(newDefFn) {}
/**
* Default dtor.
*/
virtual ~Parameter() {}
/**
* Set the member variable of \a ib to \a val.
*/
virtual void tset(InterfacedBase & ib, string val)
const;
/**
* Return the value of the member variable of ib.
*/
virtual string tget(const InterfacedBase & ib) const
;
/**
* Return the default value for the member variable of \a ib.
*/
virtual string tdef(const InterfacedBase & ib) const
;
/**
* Give a pointer to a member function to be used by tset().
*/
void setSetFunction(SetFn sf) { theSetFn = sf; }
/**
* Give a pointer to a member function to be used by tget().
*/
void setGetFunction(GetFn gf) { theGetFn = gf; }
/**
* Give a pointer to a member function to be used by tdef().
*/
void setDefaultFunction(GetFn df) { theDefFn = df; }
/**
* Print a description to be included in the Doxygen documentation
* to the given \a stream.
*/
virtual void doxygenDescription(ostream & stream) const;
private:
/**
* The pointer to the member variable.
*/
Member theMember;
/**
* Default, minimum and maximum values to be used if no
* corresponding member function pointers are given.
*/
string theDef;
/**
* A pointer to a member function to be used by tset().
*/
SetFn theSetFn;
/**
* Pointer to member function to be used by tget().
*/
GetFn theGetFn;
/**
* Pointer to member function to be used by tdef().
*/
GetFn theDefFn;
};
}
#ifndef ThePEG_TEMPLATES_IN_CC_FILE
#include "Parameter.tcc"
#endif
#endif /* ThePEG_Parameter_H */
|