Changes between Version 2 and Version 3 of League/Settings


Ignore:
Timestamp:
Feb 17, 2011, 3:19:16 AM (10 years ago)
Author:
vadim.godunko
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • League/Settings

    v2 v3  
    44
    55== Example ==
     6
     7=== Typical use ===
     8
     9Here is example of typical use of Settings. Settings object is initialize automatically and provide transparent access to set of settings with fallbacks mechanism. Type of settings storage (INI files, Windows Registry) and number of settings storages used by fallbacks mechanism depends from operating system and its configuration.
    610
    711{{{
     
    1822       renames League.Strings.To_Universal_String;
    1923
    20    X : League.Settings.Settings;
    21    V : League.Values.Value;
     24begin
     25   --  Set organization name and domain, application name.
     26
     27   League.Application.Set_Organization_Name (+"My Software");
     28   League.Application.Set_Organization_Domain (+"example.com");
     29   League.Application.Set_Application_Name (+"Settings Example");
     30
     31   declare
     32      S : League.Settings.Settings;
     33      V : League.Values.Value;
     34
     35   begin
     36      --  Setting value
     37
     38      League.Values.Strings.Set (V, +"value");
     39      S.Set_Value (+"section/key", V);
     40
     41      --  Getting value
     42
     43      Ada.Wide_Wide_Text_IO.Put_Line
     44       (League.Values.Strings.Get
     45         (S.Value (+"section/key")).To_Wide_Wide_String);
     46   end;
     47end Main;
     48}}}
     49
     50=== Application and Organization settings and Fallbacks ===
     51
     52This example highlights creation of organization settings and shows how they are used by fallbacks mechanism.
     53
     54{{{
     55with Ada.Wide_Wide_Text_IO;
     56
     57with League.Settings;
     58with League.Strings;
     59with League.Values.Strings;
     60
     61procedure Main is
     62
     63   function "+"
     64    (Item : Wide_Wide_String) return League.Strings.Universal_String
     65       renames League.Strings.To_Universal_String;
    2266
    2367begin
    24    X.Load ("my.ini");
     68   --  Set organization name and domain, application name.
    2569
    26    Ada.Wide_Wide_Text_IO.Put_Line
    27     (League.Values.Strings.Get (X.Value (+"tst/my")).To_Wide_Wide_String);
     70   League.Application.Set_Organization_Name (+"My Software");
     71   League.Application.Set_Organization_Domain (+"example.com");
     72   League.Application.Set_Application_Name (+"Settings Example");
    2873
    29    League.Values.Strings.Set (V, +"Мой текст");
    30    X.Set_Value (+"test/your", V);
     74   --  Create organization settings
    3175
    32    X.Save ("new.ini");
     76   declare
     77      S : League.Settings.Settings
     78        := League.Settings.Create (+"My Software", +"example.com");
     79      V : League.Values.Value;
     80
     81   begin
     82      --  Setting value
     83
     84      League.Values.Strings.Set (V, +"organization_value");
     85      S.Set_Value (+"section/override_key", V);
     86
     87      League.Values.Strings.Set (V, +"organization_value");
     88      S.Set_Value (+"section/derived_key", V);
     89   end;
     90
     91   --  Create application settings
     92
     93   declare
     94      S : League.Settings.Settings
     95        := League.Settings.Create
     96            (+"My Software", +"example.com", +"Settings Example");
     97      V : League.Values.Value;
     98
     99   begin
     100      --  Setting value
     101
     102      League.Values.Strings.Set (V, +"application_value");
     103      S.Set_Value (+"section/override_key", V);
     104   end;
     105
     106   --  Show work of fallbacks mechanism
     107
     108   declare
     109      S : League.Settings.Settings;
     110      V : League.Values.Value;
     111
     112   begin
     113      --  Getting value
     114
     115      Ada.Wide_Wide_Text_IO.Put_Line
     116       (League.Values.Strings.Get
     117         (S.Value (+"section/override_key")).To_Wide_Wide_String);
     118
     119      --  Getting value
     120
     121      Ada.Wide_Wide_Text_IO.Put_Line
     122       (League.Values.Strings.Get
     123         (S.Value (+"section/derived_key")).To_Wide_Wide_String);
     124   end;
    33125end Main;
    34126}}}