/usr/include/classad/value.h is in libclassad-dev 8.2.3~dfsg.1-6.
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 | /***************************************************************
*
* Copyright (C) 1990-2007, Condor Team, Computer Sciences Department,
* University of Wisconsin-Madison, WI.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may
* obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
***************************************************************/
#ifndef __CLASSAD_VALUE_H__
#define __CLASSAD_VALUE_H__
#include "classad/common.h"
#include "classad/util.h"
#include "classad/classad_stl.h"
namespace classad {
class Literal;
class ExprList;
class ClassAd;
/// Represents the result of an evaluation.
class Value
{
public:
/// Value types
enum ValueType {
NULL_VALUE = 0,
/** The error value */ ERROR_VALUE = 1<<0,
/** The undefined value */ UNDEFINED_VALUE = 1<<1,
/** A boolean value (false, true)*/ BOOLEAN_VALUE = 1<<2,
/** An integer value */ INTEGER_VALUE = 1<<3,
/** A real value */ REAL_VALUE = 1<<4,
/** A relative time value */ RELATIVE_TIME_VALUE = 1<<5,
/** An absolute time value */ ABSOLUTE_TIME_VALUE = 1<<6,
/** A string value */ STRING_VALUE = 1<<7,
/** A classad value */ CLASSAD_VALUE = 1<<8,
/** A list value (not owned here)*/ LIST_VALUE = 1<<9,
/** A list value (owned via shared_ptr)*/ SLIST_VALUE = 1<<10
};
/// Number factors
enum NumberFactor {
/** No factor specified */ NO_FACTOR= 0,
/** Byte factor */ B_FACTOR = 1,
/** Kilo factor */ K_FACTOR = 2,
/** Mega factor */ M_FACTOR = 3,
/** Giga factor */ G_FACTOR = 4,
/** Terra factor*/ T_FACTOR = 5
};
/// Values of number multiplication factors
static const double ScaleFactor[];
/// Constructor
Value();
/// Copy Constructor
Value(const Value &value);
/// Destructor
~Value();
/// Assignment operator
Value& operator=(const Value &value);
/** Discards the previous value and sets the value to UNDEFINED */
void Clear (void);
/** Copies the value of another value object.
@param v The value copied from.
*/
void CopyFrom( const Value &v );
/** Sets a boolean value; previous value discarded.
@param b The boolean value.
*/
void SetBooleanValue(bool b);
/** Sets a real value; previous value discarded.
@param r The real value.
*/
void SetRealValue(double r);
/** Sets an integer value; previous value discarded.
@param i The integer value.
*/
void SetIntegerValue(long long i);
/** Sets the undefined value; previous value discarded.
*/
void SetUndefinedValue(void);
/** Sets the error value; previous value discarded.
*/
void SetErrorValue(void);
/** Sets an expression list value; previous value discarded. Unlike the
version of this function that takes a raw ExprList pointer, this one
takes (shared) ownership over the list. This list will be deleted
when the last copy of this shared_ptr goes away.
@param l The list value.
*/
void SetListValue(classad_shared_ptr<ExprList> l);
/** Sets an expression list value; previous value discarded. Unlike the
version of this function that takes a shared_ptr, you still own the ExprList:: it
is not owned by the Value class, so it is your responsibility to delete it.
@param l The list value.
*/
void SetListValue(ExprList* l);
/** Sets a ClassAd value; previous value discarded. You still own the ClassA:, it
is not owned by the Value class, so it is your responsibility to delete it.
@param c The ClassAd value.
*/
void SetClassAdValue(ClassAd* c);
/** Sets a string value; previous value discarded.
@param str The string value.
*/
void SetStringValue( const std::string &str );
/** Sets a string value; previous value discarded. The string is copied
so you may feel free to delete the original if you wish.
@param str The string value.
*/
void SetStringValue( const char *str );
/** Sets an absolute time value in seconds since the UNIX epoch, & the
time zone it's measured in.
@param secs - Absolute Time Literal(seconds since the UNIX epoch, timezone offset) .
*/
void SetAbsoluteTimeValue( abstime_t secs );
/** Sets a relative time value.
@param secs Number of seconds.
*/
void SetRelativeTimeValue( time_t secs );
void SetRelativeTimeValue( double secs );
/** Gets the type of the value.
@return The value type.
@see ValueType
*/
inline ValueType GetType() const { return valueType; }
/** Checks if the value is boolean.
@param b The boolean value if the value is boolean.
@return true iff the value is boolean.
*/
inline bool IsBooleanValue(bool& b) const;
/** Checks if the value is boolean.
@return true iff the value is boolean.
*/
inline bool IsBooleanValue() const;
/** Checks if the value is boolean or something considered
equivalent by implicit conversion (e.g. a number), if
old ClassAd evaluation semantics are being used. If they're
not being used, this method behaves like IsBooleanValue().
@param b The boolean value if return is true.
@return true iff the value is boolean or equivalent
*/
bool IsBooleanValueEquiv(bool &b) const;
/** Checks if the value is integral.
@param i The integer value if the value is integer.
If the type of i is smaller than a long long, the value
may be truncated.
@return true iff the value is an integer.
*/
inline bool IsIntegerValue(int &i) const;
inline bool IsIntegerValue(long &i) const;
inline bool IsIntegerValue(long long &i) const;
/** Checks if the value is integral.
@return true iff the value is an integer.
*/
inline bool IsIntegerValue() const;
/** Checks if the value is real.
@param r The real value if the value is real.
@return true iff the value is real.
*/
inline bool IsRealValue(double &r) const;
/** Checks if the value is real.
@return true iff the value is real.
*/
inline bool IsRealValue() const;
/** Checks if the value is a string.
@param str A reference to a string object, which is filled with the
string value.
@return true iff the value is a string.
*/
bool IsStringValue( std::string &str ) const;
/** Checks if the value is a string.
@param str A reference to a C string, which will point to the
string value. This pointer must <b>not</b> be deallocated or
tampered with.
@return true iff the value is a string.
*/
bool IsStringValue( const char *&str ) const;
/** Checks if the value is a string and provides a copy of it in a buffer you provide
@param str A buffer to hold the string value.
@param len The size of the buffer.
@return true iff the value is a string.
*/
bool IsStringValue( char *str, int len ) const;
/** Returns length of the string instead of the string
@param size This is filled in with the size of the string
@return true iff the value is string.
*/
inline bool IsStringValue( int &size ) const;
/** Checks if the value is a string.
@return true iff the value is string.
*/
inline bool IsStringValue() const;
/** Checks if the value is an expression list.
@param l The expression list if the value is an expression list.
@return true iff the value is an expression list.
*/
inline bool IsListValue(const ExprList*& l) const;
/** Checks if the value is an expression list. The ExprList returned is
the original list put into the Value, so you only own it if you own
the original. If the original was put into this Value as a shared_ptr,
the shared_ptr still owns it (i.e. don't delete this pointer or
make a new shared_ptr for it). Consider using IsSListValue() instead.
@param l The expression list if the value is an expression list.
@return true iff the value is an expression list.
*/
inline bool IsListValue(ExprList*& l);
/** Checks if the value is an expression list.
@param l A shared_ptr to the expression list if the value is an expression list.
Note that if the list was not set via a shared_ptr, a copy of the
list will be made and this Value will convert from type LIST_VALUE
to SLIST_VALUE as a side-effect.
@return true iff the value is an expression list
*/
bool IsSListValue(classad_shared_ptr<ExprList>& l);
/** Checks if the value is an expression list.
@return true iff the value is an expression list.
*/
inline bool IsListValue() const;
/** Checks if the value is a ClassAd.
@param c The ClassAd if the value is a ClassAd.
@return true iff the value is a ClassAd.
*/
inline bool IsClassAdValue(const ClassAd *&c) const;
/** Checks if the value is a ClassAd. The ClassAd returned is
the original list put into the ClassAd, so you only own it if you own
the original.
@param c The ClassAd if the value is a ClassAd.
@return true iff the value is a ClassAd.
*/
inline bool IsClassAdValue(ClassAd *&c) const;
/** Checks if the value is a ClassAd.
@return true iff the value is a ClassAd value.
*/
inline bool IsClassAdValue() const;
/** Checks if the value is the undefined value.
@return true iff the value if the undefined value.
*/
inline bool IsUndefinedValue() const;
/** Checks if the value is the error value.
@return true iff the value if the error value.
*/
inline bool IsErrorValue() const;
/** Checks if the value is exceptional.
@return true iff the value is either undefined or error.
*/
inline bool IsExceptional() const;
/** Checks if the value is numerical.
This includes booleans, which can be used in arithmetic.
@return true iff the value is a number
*/
bool IsNumber () const;
/** Checks if the value is numerical. If the value is a real, it is
converted to an integer through truncation.
If the value is a boolean, it is converted to 0 (for False)
or 1 (for True).
@param i The integer value of the value if the value is a number.
If the type of i is smaller than a long long, the value
may be truncated.
@return true iff the value is a number
*/
bool IsNumber (int &i) const;
bool IsNumber (long &i) const;
bool IsNumber (long long &i) const;
/** Checks if the value is numerical. If the value is an integer, it
is promoted to a real.
If the value is a bollean, it is converted to 0.0 (for False)
or 1.0 (for True).
@param r The real value of the value if the value is a number.
@return true iff the value is a number
*/
bool IsNumber (double &r) const;
/** Checks if the value is an absolute time value.
@return true iff the value is an absolute time value.
*/
bool IsAbsoluteTimeValue( ) const;
/** Checks if the value is an absolute time value.
@param secs - Absolute time literal (Number of seconds since the UNIX epoch,timezone offset).
@return true iff the value is an absolute time value.
*/
bool IsAbsoluteTimeValue( abstime_t& secs ) const;
/** Checks if the value is a relative time value.
@return true iff the value is a relative time value
*/
bool IsRelativeTimeValue( ) const;
/** Checks if the value is a relative time value.
@param secs Number of seconds
@return true iff the value is a relative time value
*/
bool IsRelativeTimeValue( double& secs ) const;
bool IsRelativeTimeValue( time_t& secs ) const;
bool SameAs(const Value &otherValue) const;
friend bool operator==(const Value &value1, const Value &value2);
friend std::ostream& operator<<(std::ostream &stream, Value &value);
private:
void _Clear();
friend class Literal;
friend class ClassAd;
friend class ExprTree;
ValueType valueType; // the type of the value
union {
bool booleanValue;
long long integerValue;
double realValue;
ExprList *listValue;
classad_shared_ptr<ExprList> *slistValue;
ClassAd *classadValue;
double relTimeValueSecs;
abstime_t *absTimeValueSecs;
std::string *strValue;
};
};
bool convertValueToRealValue(const Value value, Value &realValue);
bool convertValueToIntegerValue(const Value value, Value &integerValue);
bool convertValueToStringValue(const Value value, Value &stringValue);
// implementations of the inlined functions
inline bool Value::
IsBooleanValue( bool& b ) const
{
b = booleanValue;
return( valueType == BOOLEAN_VALUE );
}
inline bool Value::
IsBooleanValue() const
{
return( valueType == BOOLEAN_VALUE );
}
inline bool Value::
IsIntegerValue (int &i) const
{
i = (int)integerValue;
return (valueType == INTEGER_VALUE);
}
inline bool Value::
IsIntegerValue (long &i) const
{
i = (long)integerValue;
return (valueType == INTEGER_VALUE);
}
inline bool Value::
IsIntegerValue (long long &i) const
{
i = integerValue;
return (valueType == INTEGER_VALUE);
}
inline bool Value::
IsIntegerValue () const
{
return (valueType == INTEGER_VALUE);
}
inline bool Value::
IsRealValue (double &r) const
{
r = realValue;
return (valueType == REAL_VALUE);
}
inline bool Value::
IsRealValue () const
{
return (valueType == REAL_VALUE);
}
inline bool Value::
IsListValue( const ExprList *&l) const
{
if (valueType == LIST_VALUE) {
l = listValue;
return true;
} else if (valueType == SLIST_VALUE) {
l = slistValue->get();
return true;
} else {
return false;
}
}
inline bool Value::
IsListValue( ExprList *&l)
{
if (valueType == LIST_VALUE) {
l = listValue;
return true;
} else if (valueType == SLIST_VALUE) {
l = slistValue->get();
return true;
} else {
return false;
}
}
inline bool Value::
IsListValue () const
{
return (valueType == LIST_VALUE || valueType == SLIST_VALUE);
}
inline bool Value::
IsStringValue() const
{
return (valueType == STRING_VALUE);
}
inline bool Value::
IsStringValue( const char *&s ) const
{
// We want to be careful not to copy it in here.
// People may accumulate in the "s" after this call,
// So it best to only touch it if it exists.
// (Example: the strcat classad function)
if (valueType == STRING_VALUE) {
s = strValue->c_str( );
return true;
} else {
return false;
}
}
inline bool Value::
IsStringValue( char *s, int len ) const
{
if( valueType == STRING_VALUE ) {
strncpy( s, strValue->c_str( ), len );
return( true );
}
return( false );
}
inline bool Value::
IsStringValue( std::string &s ) const
{
if ( valueType == STRING_VALUE ) {
s = *strValue;
return true;
} else {
return false;
}
}
inline bool Value::
IsStringValue( int &size ) const
{
if (valueType == STRING_VALUE) {
size = strValue->size();
return true;
} else {
size = -1;
return false;
}
}
inline bool Value::
IsClassAdValue(const ClassAd *&ad) const
{
if ( valueType == CLASSAD_VALUE ) {
ad = classadValue;
return true;
} else {
return false;
}
}
inline bool Value::
IsClassAdValue(ClassAd *&ad) const
{
if ( valueType == CLASSAD_VALUE ) {
ad = classadValue;
return true;
} else {
return false;
}
}
inline bool Value::
IsClassAdValue() const
{
return( valueType == CLASSAD_VALUE );
}
inline bool Value::
IsUndefinedValue (void) const
{
return (valueType == UNDEFINED_VALUE);
}
inline bool Value::
IsErrorValue(void) const
{
return (valueType == ERROR_VALUE);
}
inline bool Value::
IsExceptional(void) const
{
return( valueType == UNDEFINED_VALUE || valueType == ERROR_VALUE );
}
inline bool Value::
IsAbsoluteTimeValue( ) const
{
return( valueType == ABSOLUTE_TIME_VALUE );
}
inline bool Value::
IsAbsoluteTimeValue( abstime_t &secs ) const
{
if ( valueType == ABSOLUTE_TIME_VALUE ) {
secs = *absTimeValueSecs;
return true;
} else {
return false;
}
}
inline bool Value::
IsRelativeTimeValue( ) const
{
return( valueType == RELATIVE_TIME_VALUE );
}
inline bool Value::
IsRelativeTimeValue( double &secs ) const
{
secs = relTimeValueSecs;
return( valueType == RELATIVE_TIME_VALUE );
}
inline bool Value::
IsRelativeTimeValue( time_t &secs ) const
{
secs = (int) relTimeValueSecs;
return( valueType == RELATIVE_TIME_VALUE );
}
inline bool Value::
IsNumber( ) const
{
return( valueType==INTEGER_VALUE || valueType==REAL_VALUE );
}
} // classad
#endif//__CLASSAD_VALUE_H__
|