Changeset 16

Show
Ignore:
Timestamp:
09/24/07 16:36:26 (1 year ago)
Author:
aarti_pl
Message:

cleanups + comments

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/npo/doost/core/Any.d

    r14 r16  
    2222 
    2323    /*************************************************************************** 
     24        Copy operator 
    2425     **************************************************************************/ 
    2526    typeof(this) dup() { 
  • branches/npo/doost/util/config/CommandLineStorage.d

    r14 r16  
    137137    Class thrown when there are too many positional options. 
    138138 ******************************************************************************/ 
    139 class TooManyPositionalOptionsException : ProgramOptionsException { 
    140 public: 
    141     this(char[] what) { 
    142         super(what); 
    143     } 
    144 
    145  
    146 //------------------------------------------------------------------------------ 
    147  
    148 /******************************************************************************* 
    149     Class thrown when there are too few positional options. 
    150  ******************************************************************************/ 
    151 class TooFewPositionalOptionsException : ProgramOptionsException { 
     139class PositionalOptionException : ProgramOptionsException { 
    152140public: 
    153141    this(char[] what) { 
     
    172160class InvalidCommandLineStyleException : ProgramOptionsException { 
    173161public: 
     162    /*************************************************************************** 
     163        Constructor 
     164     **************************************************************************/ 
    174165    this(char[] msg) { 
    175166        super(msg); 
     
    193184 ******************************************************************************/ 
    194185abstract class CommandLineOption : SpecialOption { 
     186    /*************************************************************************** 
     187        See: Option 
     188     **************************************************************************/ 
    195189    typeof(this) dup(); 
    196190} 
     
    199193 
    200194/******************************************************************************* 
     195    This class allows to get application binary path, which is passed by 
     196    system to binary program 
    201197 ******************************************************************************/ 
    202198class SelfPath : CommandLineOption { 
    203199public: 
     200    /*************************************************************************** 
     201        Constructor 
     202     **************************************************************************/ 
    204203    this() { 
    205204        m_semantic = new TypedValue!(char[]); 
     
    208207    } 
    209208 
     209    /*************************************************************************** 
     210        See: Option 
     211     **************************************************************************/ 
    210212    override typeof(this) dup() { 
    211213        auto result = new typeof(this); 
     
    214216    } 
    215217 
     218    /*************************************************************************** 
     219        See: Option 
     220     **************************************************************************/ 
    216221    alias Option.semantic semantic; 
    217222    override void semantic(ValueSemantic s) {assert(false, "You can not change semantic for SelfPath!");} 
    218223 
    219224    /*************************************************************************** 
    220      **************************************************************************/ 
    221     char[] optionTypeName() { 
     225        See: Option 
     226     **************************************************************************/ 
     227    override char[] optionTypeName() { 
    222228        return typeof(this).stringof; 
    223229    } 
     
    227233 
    228234/******************************************************************************* 
     235    This class allows to get application directory path, which is passed by 
     236    system to binary program 
    229237 ******************************************************************************/ 
    230238class SelfDir : CommandLineOption { 
    231239public: 
     240    /*************************************************************************** 
     241        Constructor 
     242     **************************************************************************/ 
    232243    this() { 
    233244        m_semantic = new TypedValue!(char[]); 
     
    236247    } 
    237248 
     249    /*************************************************************************** 
     250        See: Option 
     251     **************************************************************************/ 
    238252    override typeof(this) dup() { 
    239253        auto result = new typeof(this); 
     
    242256    } 
    243257 
     258    /*************************************************************************** 
     259        See: Option 
     260     **************************************************************************/ 
    244261    alias Option.semantic semantic; 
    245262    override void semantic(ValueSemantic s) {assert(false, "You can not change semantic for SelfDir!");} 
    246263 
    247264    /*************************************************************************** 
     265        See: Option 
    248266     **************************************************************************/ 
    249267    char[] optionTypeName() { 
     
    255273 
    256274/******************************************************************************* 
     275    This class allows to get application binary name, which is passed by 
     276    system to binary program 
    257277 ******************************************************************************/ 
    258278class SelfName : CommandLineOption { 
    259279public: 
     280    /*************************************************************************** 
     281        Constructor 
     282     **************************************************************************/ 
    260283    this() { 
    261284        m_semantic = new TypedValue!(char[]); 
     
    264287    } 
    265288 
     289    /*************************************************************************** 
     290        See: Option 
     291     **************************************************************************/ 
    266292    override typeof(this) dup() { 
    267293        auto result = new typeof(this); 
     
    270296    } 
    271297 
     298    /*************************************************************************** 
     299        See: Option 
     300     **************************************************************************/ 
    272301    alias Option.semantic semantic; 
    273302    override void semantic(ValueSemantic s) {assert(false, "You can not change semantic for SelfName!");} 
    274303 
    275304    /*************************************************************************** 
     305        See: Option 
    276306     **************************************************************************/ 
    277307    char[] optionTypeName() { 
     
    304334    } 
    305335 
     336    /*************************************************************************** 
     337        See: Option 
     338     **************************************************************************/ 
    306339    override typeof(this) dup() { 
    307340        auto result = new typeof(this); 
     
    312345    } 
    313346 
     347    /*************************************************************************** 
     348        See: Option 
     349     **************************************************************************/ 
    314350    override void description(char[] s) {assert(false);} 
    315351    override char[] description() {assert(false);} 
     352 
     353    /*************************************************************************** 
     354        See: Option 
     355     **************************************************************************/ 
    316356    override ValueSemantic semantic() {assert(false);} 
    317357    override void semantic(ValueSemantic s) {assert(false);} 
     358 
     359    /*************************************************************************** 
     360        See: Option 
     361     **************************************************************************/ 
    318362    override char[] key(char[] name) {return null;} 
    319363 
     
    411455public: 
    412456    /*************************************************************************** 
    413         Copy operator 
     457        Constructor 
     458     **************************************************************************/ 
     459    this() { 
     460    } 
     461 
     462    /*************************************************************************** 
     463        Constructor 
     464 
     465        Params: 
     466            caption = first part of printable description of options 
     467                      given by user 
     468     **************************************************************************/ 
     469    this(char[] caption) { 
     470        m_caption = caption; 
     471    } 
     472 
     473    /*************************************************************************** 
     474        See: OptonsDescription 
    414475     **************************************************************************/ 
    415476    typeof(this) dup() { 
     
    418479 
    419480    /*************************************************************************** 
    420      **************************************************************************/ 
    421     this() { 
    422     } 
    423  
    424     /*************************************************************************** 
    425      **************************************************************************/ 
    426     this(char[] caption) { 
    427         m_caption = caption; 
    428     } 
    429  
    430     /*************************************************************************** 
     481        See: OptonsDescription 
    431482     **************************************************************************/ 
    432483    EasyInit!(CommandLineOptions) addOptions() { 
     
    465516 
    466517/******************************************************************************* 
     518    This storage parses array of command line arguments. Depending on style, 
     519    first argument can be treated as path to binary executable. 
    467520 ******************************************************************************/ 
    468521class CommandLineStorage : ConcreteStorage { 
     
    484537 
    485538    /*************************************************************************** 
    486      **************************************************************************/ 
    487     this(RegularOptions od, char[][] args) 
     539        Constructor 
     540 
     541        Params: 
     542            ro = description of options 
     543            args = array of command line arguments 
     544     **************************************************************************/ 
     545    this(RegularOptions ro, char[][] args) 
    488546    in { 
    489         assert(od !is null); 
     547        assert(ro !is null); 
    490548        assert(args !is null); 
    491549    } 
     
    493551        m_args = args.dup; 
    494552        m_style = Style.DefaultStyle; 
    495         m_regular = od.dup; 
     553        m_regular = ro.dup; 
    496554        m_special = null; 
    497555        m_desc = m_regular; 
     
    601659 
    602660protected: 
    603  
    604661    /*************************************************************************** 
    605662        See: BaseStorage 
     
    655712 
    656713                if (position >= positional.maxTotalCount) 
    657                         throw new TooManyPositionalOptionsException("too many positional options"); 
     714                        throw new PositionalOptionException("Too many positional options"); 
    658715 
    659716                char[] name = positional.nameForPosition(position); 
     
    703760 
    704761    /*************************************************************************** 
     762        See: BaseStorage 
    705763     **************************************************************************/ 
    706764    override void disconnect() { 
     
    741799 
    742800    /*************************************************************************** 
     801        Parses long options: --name 
    743802     **************************************************************************/ 
    744803    ParsedOption[] parseLongOption(ref char[][] args) { 
     
    796855 
    797856    /*************************************************************************** 
     857        Parses short options: -n 
    798858     **************************************************************************/ 
    799859    ParsedOption[] parseShortOption(ref char[][] args) { 
     
    847907 
    848908    /*************************************************************************** 
     909        Parses dos options: /n 
    849910     **************************************************************************/ 
    850911    ParsedOption[] parseDosOption(ref char[][] args) { 
     
    853914        if (args[0].length >= 2 && args[0][0] == '/') { 
    854915            char[] tok = consumeToken(args); 
    855             char[] name = "-" ~ tok[1]; 
     916            char[] name = [tok[1]]; 
    856917            char[] adjacent = tok[2..$]; 
    857918 
     
    931992    } 
    932993 
    933     // Fields 
     994    //---------------------------- Fields -------------------------------------- 
    934995    char[][] m_args; 
    935996    Style m_style; 
  • branches/npo/doost/util/config/ConfigFileStorage.d

    r14 r16  
    6161            codepage = codepage of file (default = unicode utf8/utf16/utf32) 
    6262     **************************************************************************/ 
    63     this(RegularOptions desc, char[] file, int codepage=-1) 
     63    this(RegularOptions ro, char[] file, int codepage=-1) 
    6464    in { 
    65         assert(desc !is null); 
     65        assert(ro !is null); 
    6666        assert(file != ""); 
    6767    } 
    6868    body { 
    6969        m_file = file; 
    70         m_regular=desc.dup; 
     70        m_regular=ro.dup; 
    7171        m_desc = m_regular; 
    7272        m_persistent = true; 
     
    8484    } 
    8585    body { 
    86         m_file = file
     86        m_file = file.dup
    8787        return this; 
    8888    } 
     
    107107 
    108108    /*************************************************************************** 
     109        See: ConcreteStorage 
    109110     **************************************************************************/ 
    110111    override OptionsMap readPhysicallyAll() { 
     
    135136 
    136137    /*************************************************************************** 
     138        See: ConcreteStorage 
    137139     **************************************************************************/ 
    138140    override Value readPhysicallyOne(char[] name) { 
     
    273275 
    274276    /*************************************************************************** 
     277        See: ConcreteStorage 
    275278     **************************************************************************/ 
    276279    override void savePhysicallyAll(OptionsMap map) { 
     
    343346 
    344347    /*************************************************************************** 
     348        See: ConcreteStorage 
    345349     **************************************************************************/ 
    346350    override void savePhysicallyOne(char[] name, in Value value) 
     
    436440            if (s[0] == '[' && s[$-1] == ']') { 
    437441                result.prefix = s[1..$-1]; 
    438                 if (result.prefix[$-1] == '.') throw new InvalidSyntaxException(s, "section can not end with dot"); 
     442                if (result.prefix[$-1] == '.') throw new InvalidConfigFileSyntaxException(s, "section can not end with dot"); 
    439443            } else { 
    440444                //Handle typed values 
     
    462466    } 
    463467 
    464     // Fields 
    465     char[] m_file; 
    466  
     468    //---------------------------- Definitions --------------------------------- 
    467469    struct FileLine { 
    468470        char[] prefix;  // "" - no prefix 
     
    471473        char[] comment; // "" - option line or empty line 
    472474    } 
     475 
     476    //---------------------------- Fields -------------------------------------- 
     477    char[] m_file; 
    473478} 
  • branches/npo/doost/util/config/DbStorage.d

    r14 r16  
    121121    } 
    122122 
     123    //---------------------------- Fields -------------------------------------- 
     124 
    123125    Database m_db; 
    124126    char[] m_table; 
  • branches/npo/doost/util/config/EnvironmentStorage.d

    r14 r16  
    2424 
    2525    /*************************************************************************** 
     26        Constructor 
     27 
     28        Params: 
     29            ro = description of options 
    2630     **************************************************************************/ 
    27     this(RegularOptions od
     31    this(RegularOptions ro
    2832    in { 
    29         assert(od !is null); 
     33        assert(ro !is null); 
    3034    } 
    3135    body { 
    32         m_regular = od.dup; 
     36        m_regular = ro.dup; 
    3337        m_desc = m_regular; 
    3438        m_defaultSyncPolicy = SyncPolicy.Direct; 
  • branches/npo/doost/util/config/Exception.d

    r14 r16  
    6363    this(char[] type, char[] name) { 
    6464        super("Duplicated '" ~ type ~ "' option definition with name: " ~ name); 
    65     } 
    66 } 
    67  
    68 //------------------------------------------------------------------------------ 
    69  
    70 /******************************************************************************* 
    71     Class thrown when there are several option values, but 
    72     user called a method which cannot return them all. 
    73  ******************************************************************************/ 
    74 class MultipleValuesException : ProgramOptionsException { 
    75 public: 
    76     this(char[] what) { 
    77         super(what); 
    7865    } 
    7966} 
  • branches/npo/doost/util/config/Option.d

    r14 r16  
    434434public: 
    435435    /*************************************************************************** 
     436        copy operator 
    436437     **************************************************************************/ 
    437438    typeof(this) dup(); 
    438  
    439     /*************************************************************************** 
    440         Copy operator 
    441      **************************************************************************/ 
    442     typeof(this) duplicate(typeof(this) result) { 
    443         result.m_caption = m_caption.dup; 
    444  
    445         foreach(opt; m_options) 
    446             result.m_options ~= opt.dup; 
    447  
    448         foreach(group; m_groups) 
    449             result.m_groups~=group.dup; 
    450  
    451         foreach(opt; result.allOptions) 
    452             register(opt, result.m_index); 
    453  
    454         return result; 
    455     } 
    456439 
    457440    /*************************************************************************** 
     
    584567protected: 
    585568    /*************************************************************************** 
     569        Copy operator implementation 
     570     **************************************************************************/ 
     571    typeof(this) duplicate(typeof(this) result) { 
     572        result.m_caption = m_caption.dup; 
     573 
     574        foreach(opt; m_options) 
     575            result.m_options ~= opt.dup; 
     576 
     577        foreach(group; m_groups) 
     578            result.m_groups~=group.dup; 
     579 
     580        foreach(opt; result.allOptions) 
     581            register(opt, result.m_index); 
     582 
     583        return result; 
     584    } 
     585 
     586    /*************************************************************************** 
     587        Applies given delegate for every OptionCharacteristic marked on 
     588        bit field 
    586589     **************************************************************************/ 
    587590    void apply(Option o, void delegate(OptionCharacteristic oc) dg) { 
     
    612615 
    613616    /*************************************************************************** 
    614         Below functions checks if adding new option or options description 
    615         will not cause duplicated options to appear. 
    616  
    617         These functions should always check if: 
     617        Function checks if adding new option will not cause duplicated options 
     618        to appear. 
     619 
     620        Function checks if: 
    618621        a. there is no other same long name 
    619622        b. there is no other same short name 
     
    626629        identifies option. 
    627630 
     631        Params: 
     632            opt - option to check 
    628633     **************************************************************************/ 
    629634 
     
    648653 
    649654    /*************************************************************************** 
     655        Checks if adding given description to current description will not cause 
     656        options conflict (uses checkOption) 
     657 
     658        Params: 
     659            desc = description of options 
    650660     **************************************************************************/ 
    651661    void checkOptions(OptionsDescription desc) { 
     
    656666    } 
    657667 
    658     //-------------------------------------------------------------------------- 
     668    //---------------------------- Fields -------------------------------------- 
    659669 
    660670    char[] m_caption; 
     
    674684public: 
    675685    /*************************************************************************** 
    676         Creates the instance 
     686        Constructor 
    677687     **************************************************************************/ 
    678688    this() { 
  • branches/npo/doost/util/config/ProgramOptions.d

    r14 r16  
    614614                                        break; 
    615615            case OAction.CLEAR:         m_variablesMap.remove(name); 
    616                                         registerEvent(this, NotifyEvent.SelfRemove, name, val); 
    617616                                        break; 
    618617        } 
  • branches/npo/doost/util/config/Value.d

    r14 r16  
    1515 
    1616/******************************************************************************* 
     17    Evaluates to true if given type is array 
    1718 ******************************************************************************/ 
    1819template isArray( T ) { 
     
    2627 
    2728/******************************************************************************* 
     29    Evaluates to same type as given for arrays, and to array for not-arrays, 
     30    char[], wchar[], dchar[]. 
    2831 ******************************************************************************/ 
    2932template compositionType(T) { 
     
    4346interface ValueSemantic { 
    4447    /*************************************************************************** 
     48        Copy operator 
    4549     **************************************************************************/ 
    4650    typeof(this) dup(); 
     
    7377 
    7478    /*************************************************************************** 
    75      **************************************************************************/ 
    76     Any compose(Any[]); 
     79        Composes array of values represented by Any into one array. Type of 
     80        resulting type is calculated by template compisitionType 
     81 
     82        Params: 
     83            values - array of Any 
     84     **************************************************************************/ 
     85    Any compose(Any[] values); 
    7786 
    7887    /*************************************************************************** 
     
    113122 
    114123    /*************************************************************************** 
     124        See: ValueSemantic 
    115125     **************************************************************************/ 
    116126    override typeof(this) dup() { 
     
    120130 
    121131    /*************************************************************************** 
     132        See: ValueSemantic 
    122133     **************************************************************************/ 
    123134    override char[] name() { 
     
    126137 
    127138    /*************************************************************************** 
     139        See: ValueSemantic 
     140 
     141        Returns: always false for UntypedValue 
    128142     **************************************************************************/ 
    129143    override bool isComposing() { 
     
    149163 
    150164    /*************************************************************************** 
     165        See: ValueSemantic 
     166 
     167        Returns: always null 
    151168     **************************************************************************/ 
    152169    override Any compose(Any[] values) { 
     
    155172 
    156173    /*************************************************************************** 
     174        See: ValueSemantic 
     175 
     176        Returns: always null 
    157177     **************************************************************************/ 
    158178    override ValueSemantic compositionSemantic() { 
     
    161181 
    162182    /*************************************************************************** 
    163         Does nothing. 
     183        See: ValueSemantic 
     184 
     185        Returns: always false 
    164186     **************************************************************************/ 
    165187    override bool applyDefault(ref Any b) { 
     
    168190 
    169191    /*************************************************************************** 
    170         Returns null for Untyped Value 
     192        See: ValueSemantic 
     193 
     194        Returns: always null 
    171195     **************************************************************************/ 
    172196    override TypeInfo type() { 
     
    175199 
    176200    /*************************************************************************** 
     201        See: ValueSemantic 
     202 
     203        Returns: always true 
    177204     **************************************************************************/ 
    178205    override bool isZeroTokens() { 
     
    199226 
    200227    /*************************************************************************** 
     228        See: ValueSemantic 
    201229     **************************************************************************/ 
    202230    override typeof(this) dup() { 
     
    212240    /*************************************************************************** 
    213241        Specifies default value, which will be used 
    214         if none is explicitly specified. The type 'T' should 
    215         provide operator<< for ostream. 
     242        if none is explicitly specified 
    216243     **************************************************************************/ 
    217244    TypedValue defaultValue(T v) { 
     
    222249 
    223250    /*************************************************************************** 
    224         Specifies default value, which will be used 
    225         if none is explicitly specified. Unlike the above overload, 
    226         the type 'T' need not provide operator<< for ostream, 
    227         but textual representation of default value must be provided 
    228         by the user. 
    229      **************************************************************************/ 
    230     TypedValue defaultValue(T v, char[] textual) { 
    231         m_default_value.assign(v); 
    232         m_default_value_as_text = textual; 
    233         return this; 
    234     } 
    235  
    236     /*************************************************************************** 
    237         Specifies that the value is composing. See the 'is_composing' 
     251        Specifies that the value is composing. See the 'isComposing' 
    238252        method for explanation. 
    239253     **************************************************************************/ 
     
    244258 
    245259    /*************************************************************************** 
     260        Returns true if option can be composed. If it is true, option can appear 
     261        many times in source and will be composed into array. 
     262 
     263        Returns: true if option is composing 
    246264     **************************************************************************/ 
    247265    override bool isComposing() { 
     
    250268 
    251269    /*************************************************************************** 
     270        Specifies that option have no value - just name. 
     271 
     272        Returns: this (chaining) 
    252273     **************************************************************************/ 
    253274    TypedValue zeroTokens() { 
     
    257278 
    258279    /*************************************************************************** 
     280        Returns true if option has only name - no value. 
     281 
     282        Returns: true if option has no value 
    259283     **************************************************************************/ 
    260284    override bool isZeroTokens() { 
     
    324348 
    325349    /*************************************************************************** 
     350        See: ValueSemantic 
     351 
     352        Returns: typeid of T 
    326353     **************************************************************************/ 
    327354    override TypeInfo type() { 
     
    337364//------------------------------------------------------------------------------ 
    338365 
    339 /** Creates a TypedValue<T> instance. This function is the primary 
    340     method to create ValueSemantic instance for a specific type, which 
    341     can later be passed to 'StandardOption's destructor. 
    342     The second overload is used when it's additionally desired to store the 
    343     value of option into program variable. 
    344 */ 
    345  
     366/******************************************************************************* 
     367    Creates a TypedValue!(T) instance. This function is the primary 
     368    method to create ValueSemantic instance for a specific type. 
     369 ******************************************************************************/ 
    346370TypedValue!(T, PARSER, STRINGIZER) define(T, alias PARSER = parseText, alias STRINGIZER = stringizeValue)(char[] pattern=null) { 
    347371    return new TypedValue!(T, PARSER)(pattern); 
     
    350374//------------------------------------------------------------------------------ 
    351375 
    352 /** Works the same way as the 'value<bool>' function, but the created 
     376/******************************************************************************* 
     377    Works the same way as the 'define!(bool)' function, but the created 
    353378    ValueSemantic won't accept any explicit value. So, if the option 
    354379    is present on the command line, the value will be 'true'. 
    355 */ 
     380 ******************************************************************************/ 
    356381TypedValue!(bool) boolSwitch() { 
    357382    auto r = new TypedValue!(bool)();