section Derived Type

type, public :: section

Section data of file INI.


Inherits

type~~section~~InheritsGraph type~section section type~option option type~section->type~option options string string type~option->string oname, ovals, ocomm

Inherited by

type~~section~~InheritedByGraph type~section section type~file_ini file_ini type~file_ini->type~section sections

Contents

Source Code


Components

TypeVisibilityAttributesNameInitial
type(option), private, allocatable:: options(:)

Section options.

character(len=:), private, allocatable:: sname

Section name.


Constructor

public interface section

Overload section name with a function returning a new (itiliazed) section instance.

  • private elemental function new_section(section_name)

    Return a new (initiliazed) section instance.

    Arguments

    TypeIntentOptionalAttributesName
    character, intent(in), optional :: section_name

    Option name.

    Return Value type(section)

    New (initiliazed) section instance.


Type-Bound Procedures

generic, public :: add => add_option, add_a_option

Add an option (scalar). Add an option (array).

  • private pure subroutine add_option(self, option_name, val, error)

    Add an option (with scalar value).

    Read more…

    Arguments

    TypeIntentOptionalAttributesName
    class(section), intent(inout) :: self

    Section data.

    character, intent(in) :: option_name

    Option name.

    class(*), intent(in) :: val

    Option value.

    integer(kind=I4P), intent(out), optional :: error

    Error code.

  • private pure subroutine add_a_option(self, option_name, val, delimiter, error)

    Add an option (with array value).

    Read more…

    Arguments

    TypeIntentOptionalAttributesName
    class(section), intent(inout) :: self

    Section data.

    character, intent(in) :: option_name

    Option name.

    class(*), intent(in) :: val(:)

    Option value.

    character, intent(in), optional :: delimiter

    Delimiter used for separating values.

    integer(kind=I4P), intent(out), optional :: error

    Error code.

procedure, private, pass(self) :: add_a_option

Add an option (array).

  • private pure subroutine add_a_option(self, option_name, val, delimiter, error)

    Add an option (with array value).

    Read more…

    Arguments

    TypeIntentOptionalAttributesName
    class(section), intent(inout) :: self

    Section data.

    character, intent(in) :: option_name

    Option name.

    class(*), intent(in) :: val(:)

    Option value.

    character, intent(in), optional :: delimiter

    Delimiter used for separating values.

    integer(kind=I4P), intent(out), optional :: error

    Error code.

procedure, private, pass(self) :: add_option

Add an option (scalar).

  • private pure subroutine add_option(self, option_name, val, error)

    Add an option (with scalar value).

    Read more…

    Arguments

    TypeIntentOptionalAttributesName
    class(section), intent(inout) :: self

    Section data.

    character, intent(in) :: option_name

    Option name.

    class(*), intent(in) :: val

    Option value.

    integer(kind=I4P), intent(out), optional :: error

    Error code.

procedure, private, pass(lhs) :: assign_section

Assignment overloading.

  • private elemental subroutine assign_section(lhs, rhs)

    Assignment between two sections.

    Arguments

    TypeIntentOptionalAttributesName
    class(section), intent(inout) :: lhs

    Left hand side.

    type(section), intent(in) :: rhs

    Rigth hand side.

generic, public :: assignment(=) => assign_section

Assignment overloading.

  • private elemental subroutine assign_section(lhs, rhs)

    Assignment between two sections.

    Arguments

    TypeIntentOptionalAttributesName
    class(section), intent(inout) :: lhs

    Left hand side.

    type(section), intent(in) :: rhs

    Rigth hand side.

procedure, public, pass(self) :: count_values

Count option value(s).

  • private elemental function count_values(self, option_name, delimiter) result(Nv)

    Get the number of values of option into section data.

    Arguments

    TypeIntentOptionalAttributesName
    class(section), intent(in) :: self

    Section data.

    character, intent(in) :: option_name

    Option name.

    character, intent(in), optional :: delimiter

    Delimiter used for separating values.

    Return Value integer(kind=I4P)

    Number of values.

procedure, public, pass(self) :: free

Free dynamic memory.

  • private elemental subroutine free(self)

    Free dynamic memory.

    Arguments

    TypeIntentOptionalAttributesName
    class(section), intent(inout) :: self

    Section data.

procedure, public, pass(self) :: free_option

Free a option.

  • private elemental subroutine free_option(self, option_name)

    Free an option.

    Arguments

    TypeIntentOptionalAttributesName
    class(section), intent(inout) :: self

    Section data.

    character, intent(in) :: option_name

    Option name.

procedure, public, pass(self) :: free_options

Free all options.

  • private elemental subroutine free_options(self)

    Free all options.

    Arguments

    TypeIntentOptionalAttributesName
    class(section), intent(inout) :: self

    Section data.

generic, public :: get => get_option, get_a_option

Get option value (scalar). Get option value (array).

  • private subroutine get_option(self, option_name, val, error)

    Get option value (scalar).

    Arguments

    TypeIntentOptionalAttributesName
    class(section), intent(in) :: self

    Section data.

    character, intent(in) :: option_name

    Option name.

    class(*), intent(inout) :: val

    Value.

    integer(kind=I4P), intent(out), optional :: error

    Error code.

  • private subroutine get_a_option(self, option_name, val, delimiter, error)

    Procedure for getting option value (array).

    Arguments

    TypeIntentOptionalAttributesName
    class(section), intent(in) :: self

    Section data.

    character, intent(in) :: option_name

    Option name.

    class(*), intent(inout) :: val(1:)

    Value.

    character, intent(in), optional :: delimiter

    Delimiter used for separating values.

    integer(kind=I4P), intent(out), optional :: error

    Error code.

procedure, private, pass(self) :: get_a_option

Get option value (array).

  • private subroutine get_a_option(self, option_name, val, delimiter, error)

    Procedure for getting option value (array).

    Arguments

    TypeIntentOptionalAttributesName
    class(section), intent(in) :: self

    Section data.

    character, intent(in) :: option_name

    Option name.

    class(*), intent(inout) :: val(1:)

    Value.

    character, intent(in), optional :: delimiter

    Delimiter used for separating values.

    integer(kind=I4P), intent(out), optional :: error

    Error code.

procedure, private, pass(self) :: get_option

Get option value (scalar).

  • private subroutine get_option(self, option_name, val, error)

    Get option value (scalar).

    Arguments

    TypeIntentOptionalAttributesName
    class(section), intent(in) :: self

    Section data.

    character, intent(in) :: option_name

    Option name.

    class(*), intent(inout) :: val

    Value.

    integer(kind=I4P), intent(out), optional :: error

    Error code.

procedure, public, pass(self) :: has_options

Inquire if section has options.

  • private elemental function has_options(self)

    Inquire is section has options (at least one).

    Arguments

    TypeIntentOptionalAttributesName
    class(section), intent(in) :: self

    Section data.

    Return Value logical

    Inquire result.

procedure, public, pass(self) :: index => index_option

Return the index of an option.

  • private elemental function index_option(self, option_name, back) result(ind)

    Return the index of the option matching the name passed.

    Read more…

    Arguments

    TypeIntentOptionalAttributesName
    class(section), intent(in) :: self

    Section data.

    character, intent(in) :: option_name

    Option name.

    logical, intent(in), optional :: back

    If back appears with the value true, the last matching index is returned.

    Return Value integer(kind=I4P)

    Index of searched section.

procedure, public, pass(self) :: loop

Loop over options.

  • private function loop(self, option_pairs) result(again)

    Loop returning option name/value defined into section.

    Arguments

    TypeIntentOptionalAttributesName
    class(section), intent(in) :: self

    Section data.

    character(len=:), intent(out), allocatable:: option_pairs(:)

    Couples option name/value [1:2].

    Return Value logical

    Flag continuing the loop.

procedure, public, pass(self) :: max_chars_len

Return max len of option-name/values on all options.

  • private elemental function max_chars_len(self)

    Return the maximum number of characters between option-name/option-values on all options.

    Arguments

    TypeIntentOptionalAttributesName
    class(section), intent(in) :: self

    Section data.

    Return Value integer(kind=I4P)

    Inquire result.

procedure, public, pass(self) :: name

Return section name.

  • private pure function name(self)

    Return section name.

    Arguments

    TypeIntentOptionalAttributesName
    class(section), intent(in) :: self

    Section data.

    Return Value character(len=len)

    Section data.

generic, public :: operator(==) => section_eq_string, section_eq_character

Equal operator overloading.

  • private elemental function section_eq_string(lhs, rhs) result(is_it)

    Equal to string logical operator.

    Arguments

    TypeIntentOptionalAttributesName
    class(section), intent(in) :: lhs

    Left hand side.

    type(string), intent(in) :: rhs

    Right hand side.

    Return Value logical

    Opreator test result.

  • private elemental function section_eq_character(lhs, rhs) result(is_it)

    Equal to character logical operator.

    Arguments

    TypeIntentOptionalAttributesName
    class(section), intent(in) :: lhs

    Left hand side.

    character(kind=CK,len=*), intent(in) :: rhs

    Right hand side.

    Return Value logical

    Opreator test result.

procedure, public, pass(self) :: option_pairs

Return an option pairs.

  • private pure subroutine option_pairs(self, option_index, pairs)

    Return an option pairs.

    Arguments

    TypeIntentOptionalAttributesName
    class(section), intent(in) :: self

    Option data.

    integer, intent(in) :: option_index

    Option index.

    character(len=:), intent(out), allocatable:: pairs(:)

    Option name/values pairs.

procedure, public, pass(self) :: options_number

Return the options number.

  • private elemental function options_number(self)

    Return the options number.

    Arguments

    TypeIntentOptionalAttributesName
    class(section), intent(in) :: self

    Section data.

    Return Value integer(kind=I4P)

    Options number.

procedure, public, pass(self) :: parse

Parse section data.

  • private elemental subroutine parse(self, sep, source, error)

    Gett section data from a source string.

    Arguments

    TypeIntentOptionalAttributesName
    class(section), intent(inout) :: self

    Section data.

    character, intent(in) :: sep

    Separator of option name/value.

    type(string), intent(inout) :: source

    String containing section data.

    integer(kind=I4P), intent(out) :: error

    Error code.

procedure, private, pass(self) :: parse_name

Get section name.

  • private elemental subroutine parse_name(self, source, error)

    Get section name from a source string.

    Arguments

    TypeIntentOptionalAttributesName
    class(section), intent(inout) :: self

    Section data.

    type(string), intent(in) :: source

    String containing section data.

    integer(kind=I4P), intent(out) :: error

    Error code.

procedure, private, pass(self) :: parse_options

Get section options.

  • private elemental subroutine parse_options(self, sep, source, error)

    Get section options from a source string.

    Arguments

    TypeIntentOptionalAttributesName
    class(section), intent(inout) :: self

    Section data.

    character, intent(in) :: sep

    Separator of option name/value.

    type(string), intent(inout) :: source

    String containing section data.

    integer(kind=I4P), intent(out) :: error

    Error code.

procedure, public, pass(self) :: print => print_section

Pretty print data.

  • private subroutine print_section(self, unit, retain_comments, pref, iostat, iomsg)

    Print data with a pretty format.

    Arguments

    TypeIntentOptionalAttributesName
    class(section), intent(in) :: self

    Section data.

    integer(kind=I4P), intent(in) :: unit

    Logic unit.

    logical, intent(in) :: retain_comments

    Flag for retaining eventual comments.

    character, intent(in), optional :: pref

    Prefixing string.

    integer(kind=I4P), intent(out), optional :: iostat

    IO error.

    character, intent(out), optional :: iomsg

    IO error message.

procedure, private, nopass :: sanitize_source

Sanitize source.

  • private elemental subroutine sanitize_source(sep, source, error)

    Sanitize source.

    Read more…

    Arguments

    TypeIntentOptionalAttributesName
    character, intent(in) :: sep

    Separator of option name/value.

    type(string), intent(inout) :: source

    String containing option data.

    integer(kind=I4P), intent(out) :: error

    Error code.

procedure, public, pass(self) :: save => save_section

Save data.

  • private subroutine save_section(self, unit, retain_comments, iostat, iomsg)

    Save data.

    Arguments

    TypeIntentOptionalAttributesName
    class(section), intent(in) :: self

    Section data.

    integer(kind=I4P), intent(in) :: unit

    Logic unit.

    logical, intent(in) :: retain_comments

    Flag for retaining eventual comments.

    integer(kind=I4P), intent(out), optional :: iostat

    IO error.

    character, intent(out), optional :: iomsg

    IO error message.

procedure, private, pass(lhs) :: section_eq_character

Equal to character logical operator.

  • private elemental function section_eq_character(lhs, rhs) result(is_it)

    Equal to character logical operator.

    Arguments

    TypeIntentOptionalAttributesName
    class(section), intent(in) :: lhs

    Left hand side.

    character(kind=CK,len=*), intent(in) :: rhs

    Right hand side.

    Return Value logical

    Opreator test result.

procedure, private, pass(lhs) :: section_eq_string

Equal to string logical operator.

  • private elemental function section_eq_string(lhs, rhs) result(is_it)

    Equal to string logical operator.

    Arguments

    TypeIntentOptionalAttributesName
    class(section), intent(in) :: lhs

    Left hand side.

    type(string), intent(in) :: rhs

    Right hand side.

    Return Value logical

    Opreator test result.

generic, public :: set => set_option, set_a_option

Set option value (scalar). Set option value (array).

  • private pure subroutine set_option(self, option_name, val, error)

    Set option value (scalar).

    Arguments

    TypeIntentOptionalAttributesName
    class(section), intent(inout) :: self

    Section data.

    character, intent(in) :: option_name

    Option name.

    class(*), intent(in) :: val

    Value.

    integer(kind=I4P), intent(out), optional :: error

    Error code.

  • private pure subroutine set_a_option(self, option_name, val, delimiter, error)

    Set option value (array).

    Arguments

    TypeIntentOptionalAttributesName
    class(section), intent(inout) :: self

    Section data.

    character, intent(in) :: option_name

    Option name.

    class(*), intent(in) :: val(:)

    Value.

    character, intent(in), optional :: delimiter

    Delimiter used for separating values.

    integer(kind=I4P), intent(out), optional :: error

    Error code.

procedure, private, pass(self) :: set_a_option

Set option value (array).

  • private pure subroutine set_a_option(self, option_name, val, delimiter, error)

    Set option value (array).

    Arguments

    TypeIntentOptionalAttributesName
    class(section), intent(inout) :: self

    Section data.

    character, intent(in) :: option_name

    Option name.

    class(*), intent(in) :: val(:)

    Value.

    character, intent(in), optional :: delimiter

    Delimiter used for separating values.

    integer(kind=I4P), intent(out), optional :: error

    Error code.

procedure, private, pass(self) :: set_option

Set option value (scalar).

  • private pure subroutine set_option(self, option_name, val, error)

    Set option value (scalar).

    Arguments

    TypeIntentOptionalAttributesName
    class(section), intent(inout) :: self

    Section data.

    character, intent(in) :: option_name

    Option name.

    class(*), intent(in) :: val

    Value.

    integer(kind=I4P), intent(out), optional :: error

    Error code.

Source Code

type :: section
  !< Section data of file INI.
  private
  character(len=:), allocatable :: sname      !< Section name.
  type(option),     allocatable :: options(:) !< Section options.
  contains
    ! public methods
    generic               :: add => add_option, &   !< Add an option (scalar).
                                    add_a_option    !< Add an option (array).
    procedure, pass(self) :: count_values           !< Count option value(s).
    procedure, pass(self) :: free                   !< Free dynamic memory.
    procedure, pass(self) :: free_options           !< Free all options.
    procedure, pass(self) :: free_option            !< Free a option.
    generic               :: get => get_option, &   !< Get option value (scalar).
                                    get_a_option    !< Get option value (array).
    procedure, pass(self) :: has_options            !< Inquire if section has options.
    procedure, pass(self) :: index => index_option  !< Return the index of an option.
    procedure, pass(self) :: loop                   !< Loop over options.
    procedure, pass(self) :: max_chars_len          !< Return max len of option-name/values on all options.
    procedure, pass(self) :: name                   !< Return section name.
    procedure, pass(self) :: options_number         !< Return the options number.
    procedure, pass(self) :: option_pairs           !< Return an option pairs.
    procedure, pass(self) :: parse                  !< Parse section data.
    procedure, pass(self) :: print => print_section !< Pretty print data.
    generic               :: set => set_option, &   !< Set option value (scalar).
                                    set_a_option    !< Set option value (array).
    procedure, pass(self) :: save  => save_section  !< Save data.
    ! operators overloading
    generic :: assignment(=) => assign_section !< Assignment overloading.
    generic :: operator(==) => section_eq_string, &
                               section_eq_character !< Equal operator overloading.
    ! private methods
    procedure, private, pass(self) :: add_option      !< Add an option (scalar).
    procedure, private, pass(self) :: add_a_option    !< Add an option (array).
    procedure, private, pass(self) :: get_option      !< Get option value (scalar).
    procedure, private, pass(self) :: get_a_option    !< Get option value (array).
    procedure, private, pass(self) :: parse_name      !< Get section name.
    procedure, private, pass(self) :: parse_options   !< Get section options.
    procedure, private, nopass     :: sanitize_source !< Sanitize source.
    procedure, private, pass(self) :: set_option      !< Set option value (scalar).
    procedure, private, pass(self) :: set_a_option    !< Set option value (array).
    ! assignments
    procedure, private, pass(lhs) :: assign_section !< Assignment overloading.
    ! logical operators
    procedure, private, pass(lhs) :: section_eq_string    !< Equal to string logical operator.
    procedure, private, pass(lhs) :: section_eq_character !< Equal to character logical operator.
endtype section