Annotation of parser3/src/include/pa_dictionary.h, revision 1.20

1.1       parser      1: /** @file
                      2:        Parser: dictionary class decl.
                      3: 
1.20    ! moko        4:        Copyright (c) 2001-2012 Art. Lebedev Studio (http://www.artlebedev.com)
1.10      paf         5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.1       parser      6: */
                      7: 
                      8: #ifndef PA_DICTIONARY_H
                      9: #define PA_DICTIONARY_H
1.11      paf        10: 
1.20    ! moko       11: #define IDENT_PA_DICTIONARY_H "$Id: 2012-01-08 05:58:27 $"
1.1       parser     12: 
                     13: #include "pa_table.h"
                     14: 
                     15: /// simple dictionary, speding up lookups on contained two columned table
1.14      paf        16: class Dictionary: public PA_Object {
1.1       parser     17: public:
                     18: 
1.15      paf        19:        struct Subst {
                     20:                const char *from; size_t from_length;
                     21:                const String* to;
                     22: 
                     23:                Subst(int): from(0) {}
                     24:                Subst(const char* afrom, const String* ato): from(afrom), to(ato) {
                     25:                        from_length=strlen(afrom);
                     26:                }
                     27:                operator bool() { return from!=0; }
                     28:        };
                     29: 
1.1       parser     30:        /// construct wrapper, grabbing first letters of first column into @b first
1.14      paf        31:        Dictionary(Table& atable);
1.1       parser     32: 
1.19      misha      33:        /// construct simple dictionary within a single pair only
                     34:        Dictionary(const String& from, const String& to);
                     35: 
1.1       parser     36:        /// find first row that contains string in first column which starts @b src
1.15      paf        37:        Subst first_that_begins(const char* str) const;
1.1       parser     38: 
1.2       parser     39: private:
1.15      paf        40:        Array<Subst> substs;
1.1       parser     41: 
                     42: private:
1.19      misha      43:        void append_subst(const String* from, const String* to, const char* exception=0);
1.1       parser     44: 
1.2       parser     45:        int starting_line_of[0x100]; int constructor_line;
1.19      misha      46: 
                     47: public:
                     48:        size_t count() const { return substs.count(); }
                     49: 
                     50:        Subst get(size_t index) const { return substs.get(index); }
                     51: 
1.1       parser     52: };
                     53: 
                     54: #endif

E-mail: