A not completely F2003/2008 version of an immutable class to store primitive values: integer, real, double precision, logical, character. (To Add: complex)
This version does not use CLASS(*) or deferred length strings so that it can be used with gfortran 4.7/4.8
Initialization
TYPE(FTValue) :: r, i, s, l, d
CALL r % initValue(3.14)
CALL i % initValue(6)
CALL d % initValue(3.14d0)
CALL l % initValue(.true.)
CALL s % initValue("A string")
Destruction
call releaseFTValue(r) [Pointers]
Accessors
real = r % realValue()
int = i % integerValue()
doub = d % doublePrecisionValue()
logc = l % logicalValue()
str = s % stringValue(nChars)
Description
str = v % description()
call v % printDescription(unit)
Casting
CLASS(FTVALUE) , POINTER :: v
CLASS(FTObject), POINTER :: obj
call cast(obj,v)
The class will attempt to convert between the different types:
CALL r % initWithReal(3.14)
print *, r % stringValue(8)
Logical variables rules:
real, doublePrecision, integer values
logicalValue = .FALSE. if input = 0
logicalValue = .TRUE. if input /= 0
String values can be converted to numeric types. If the string is not a numeric, Huge(1) will be returned, for integers and NaN for reals.
@author David Kopriva
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
integer, | public, | parameter | :: | FTVALUE_NOT_INTEGER | = | HUGE(1) | |
real, | public, | parameter | :: | FTVALUE_NOT_REAL | = | HUGE(1.0) | |
double precision, | public, | parameter | :: | FTVALUE_NOT_DOUBLEPRECISION | = | HUGE(1.0D0) | |
integer, | public, | parameter | :: | FTVALUE_STRING_LENGTH | = | 512 | |
integer, | public, | parameter | :: | FT_REAL_KIND | = | SELECTED_REAL_KIND(6) | |
integer, | public, | parameter | :: | FT_DOUBLE_PRECISION_KIND | = | SELECTED_REAL_KIND(15) |
Generic Name: cast
Cast a pointer to the base class to an FTValue pointer
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(FTObject), | POINTER | :: | obj | |||
class(FTValue), | POINTER | :: | cast |
final :: destructValue |
procedure, public :: init => initFTObject | |
procedure, public, non_overridable :: copy => copyFTObject | |
procedure, public, non_overridable :: retain => retainFTObject | |
procedure, public, non_overridable :: isUnreferenced | |
procedure, public, non_overridable :: refCount | |
generic, public :: initWithValue => initWithReal, initWithDoublePrecision, initWithString, initWithLogical, initWithInteger | |
generic, public :: initWithValue => initWithQuad | |
procedure, public :: realValue | |
procedure, public :: doublePrecisionValue | |
procedure, public :: quadValue | |
procedure, public :: stringValue | |
procedure, public :: logicalValue | |
procedure, public :: integerValue | |
procedure, public :: description => FTValueDescription | |
procedure, public :: printDescription => printValueDescription | |
procedure, public :: className => valueClassName |
Get the real value stored in the object, or convert the value in the object to a real if it is of a different type.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(FTValue) | :: | self |
Get the double precision value stored in the object, or convert the value in the object to a double precision if it is of a different type.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(FTValue) | :: | self |
Get the double precision value stored in the object, or convert the value in the object to a double precision if it is of a different type.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(FTValue) | :: | self |
Get the integer value stored in the object, or convert the value in the object to an integer if it is of a different type.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(FTValue) | :: | self |
Get the logical value stored in the object, or convert the value in the object to a logical if it is of a different type.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(FTValue) | :: | self |
Get the string value of length requestedLength stored in the object, or convert the value in the object to a string of that length if it is of a different type.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(FTValue) | :: | self | ||||
integer | :: | requestedLength |
Returns the description of the value. In this case, it returns the stringValue() of the object.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(FTValue) | :: | self |
Class name returns a string with the name of the type of the object
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(FTValue) | :: | self |
Public, generic name: initwithValue()
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(FTValue) | :: | self | ||||
real | :: | v |
Public, generic name: initwithValue()
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(FTValue) | :: | self | ||||
doubleprecision | :: | v |
Public, generic name: initwithValue()
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(FTValue) | :: | self | ||||
real(kind=SELECTED_REAL_KIND(QUAD_DIGITS)) | :: | v |
Public, generic name: initwithValue()
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(FTValue) | :: | self | ||||
integer | :: | v |
Public, generic name: initwithValue()
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(FTValue) | :: | self | ||||
logical | :: | v |
Public, generic name: initwithValue()
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(FTValue) | :: | self | ||||
character(len=*) | :: | v |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(FTValue), | POINTER | :: | self |
Public, generic name: destruct()
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(FTValue) | :: | self |
Prints the description of the value to unit iUnit. In this case, it prints
the stringValue() of the object.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(FTValue) | :: | self | ||||
integer | :: | iUnit |
Generic Name: cast
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(FTObject), | POINTER | :: | obj | |||
class(FTValue), | POINTER | :: | cast |