http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/ts/ParseRules.h ---------------------------------------------------------------------- diff --git a/lib/ts/ParseRules.h b/lib/ts/ParseRules.h index 6bc7483..ce5c676 100644 --- a/lib/ts/ParseRules.h +++ b/lib/ts/ParseRules.h @@ -21,7 +21,7 @@ limitations under the License. */ -#if !defined (_ParseRules_h_) +#if !defined(_ParseRules_h_) #define _ParseRules_h_ #include <string.h> @@ -34,39 +34,39 @@ typedef unsigned int CTypeResult; // Set this to 0 to disable SI // decimal multipliers -#define USE_SI_MULTILIERS 1 - -#define is_char_BIT (1 << 0) -#define is_upalpha_BIT (1 << 1) -#define is_loalpha_BIT (1 << 2) -#define is_alpha_BIT (1 << 3) -#define is_digit_BIT (1 << 4) -#define is_ctl_BIT (1 << 5) -#define is_ws_BIT (1 << 6) -#define is_hex_BIT (1 << 7) -#define is_pchar_BIT (1 << 8) -#define is_extra_BIT (1 << 9) -#define is_safe_BIT (1 << 10) -#define is_unsafe_BIT (1 << 11) -#define is_national_BIT (1 << 12) -#define is_reserved_BIT (1 << 13) -#define is_unreserved_BIT (1 << 14) -#define is_punct_BIT (1 << 15) -#define is_end_of_url_BIT (1 << 16) -#define is_tspecials_BIT (1 << 17) -#define is_spcr_BIT (1 << 18) -#define is_splf_BIT (1 << 19) -#define is_wslfcr_BIT (1 << 20) -#define is_eow_BIT (1 << 21) -#define is_token_BIT (1 << 22) -#define is_wildmat_BIT (1 << 23) -#define is_sep_BIT (1 << 24) -#define is_empty_BIT (1 << 25) -#define is_alnum_BIT (1 << 26) -#define is_space_BIT (1 << 27) -#define is_control_BIT (1 << 28) -#define is_mime_sep_BIT (1 << 29) -#define is_http_field_name_BIT (1 << 30) +#define USE_SI_MULTILIERS 1 + +#define is_char_BIT (1 << 0) +#define is_upalpha_BIT (1 << 1) +#define is_loalpha_BIT (1 << 2) +#define is_alpha_BIT (1 << 3) +#define is_digit_BIT (1 << 4) +#define is_ctl_BIT (1 << 5) +#define is_ws_BIT (1 << 6) +#define is_hex_BIT (1 << 7) +#define is_pchar_BIT (1 << 8) +#define is_extra_BIT (1 << 9) +#define is_safe_BIT (1 << 10) +#define is_unsafe_BIT (1 << 11) +#define is_national_BIT (1 << 12) +#define is_reserved_BIT (1 << 13) +#define is_unreserved_BIT (1 << 14) +#define is_punct_BIT (1 << 15) +#define is_end_of_url_BIT (1 << 16) +#define is_tspecials_BIT (1 << 17) +#define is_spcr_BIT (1 << 18) +#define is_splf_BIT (1 << 19) +#define is_wslfcr_BIT (1 << 20) +#define is_eow_BIT (1 << 21) +#define is_token_BIT (1 << 22) +#define is_wildmat_BIT (1 << 23) +#define is_sep_BIT (1 << 24) +#define is_empty_BIT (1 << 25) +#define is_alnum_BIT (1 << 26) +#define is_space_BIT (1 << 27) +#define is_control_BIT (1 << 28) +#define is_mime_sep_BIT (1 << 29) +#define is_http_field_name_BIT (1 << 30) /* shut up the DEC compiler */ #define is_http_field_value_BIT (((CTypeResult)1) << 31) @@ -83,14 +83,13 @@ public: // whitespace definitions // //////////////////////////// - enum - { - CHAR_SP = 32, /* space */ - CHAR_HT = 9, /* horizontal tab */ - CHAR_LF = 10, /* line feed */ - CHAR_VT = 11, /* vertical tab */ - CHAR_NP = 12, /* new page */ - CHAR_CR = 13 /* carriage return */ + enum { + CHAR_SP = 32, /* space */ + CHAR_HT = 9, /* horizontal tab */ + CHAR_LF = 10, /* line feed */ + CHAR_VT = 11, /* vertical tab */ + CHAR_NP = 12, /* new page */ + CHAR_CR = 13 /* carriage return */ }; ///////////////////// @@ -99,54 +98,54 @@ public: static CTypeResult is_type(char c, uint32_t bit); - static CTypeResult is_char(char c); // ASCII 0-127 - static CTypeResult is_upalpha(char c); // A-Z - static CTypeResult is_loalpha(char c); // a-z - static CTypeResult is_alpha(char c); // A-Z,a-z - static CTypeResult is_digit(char c); // 0-9 - static CTypeResult is_ctl(char c); // ASCII 0-31,127 (includes ws) - static CTypeResult is_hex(char c); // 0-9,A-F,a-f - static CTypeResult is_ws(char c); // SP,HT - static CTypeResult is_cr(char c); // CR - static CTypeResult is_lf(char c); // LF - static CTypeResult is_spcr(char c); // SP,CR - static CTypeResult is_splf(char c); // SP,LF - static CTypeResult is_wslfcr(char c); // SP,HT,LF,CR - static CTypeResult is_tspecials(char c); // HTTP chars that need quoting - static CTypeResult is_token(char c); // token (not CTL or specials) - static CTypeResult is_extra(char c); // !,*,QUOT,(,),COMMA - static CTypeResult is_safe(char c); // [$-_.+] - static CTypeResult is_unsafe(char c); // SP,DBLQUOT,#,%,<,> - static CTypeResult is_national(char c); // {,},|,BACKSLASH,^,~,[,],` - static CTypeResult is_reserved(char c); // :,/,?,:,@,&,= - static CTypeResult is_unreserved(char c); // alpha,digit,safe,extra,nat. - static CTypeResult is_punct(char c); // !"#$%&'()*+,-./:;<>=?@_{}|~ - static CTypeResult is_end_of_url(char c); // NUL,CR,SP - static CTypeResult is_eow(char c); // NUL,CR,LF - static CTypeResult is_wildmat(char c); // \,*,?,[ - static CTypeResult is_sep(char c); // NULL,COMMA,':','!',wslfcr - static CTypeResult is_empty(char c); // wslfcr,# - static CTypeResult is_alnum(char c); // 0-9,A-Z,a-z - static CTypeResult is_space(char c); // ' ' HT,VT,NP,CR,LF - static CTypeResult is_control(char c); // 0-31 127 - static CTypeResult is_mime_sep(char c); // ()<>,;\"/[]?{} \t - static CTypeResult is_http_field_name(char c); // not : or mime_sep except for @ - static CTypeResult is_http_field_value(char c); // not CR, LF, comma, or " + static CTypeResult is_char(char c); // ASCII 0-127 + static CTypeResult is_upalpha(char c); // A-Z + static CTypeResult is_loalpha(char c); // a-z + static CTypeResult is_alpha(char c); // A-Z,a-z + static CTypeResult is_digit(char c); // 0-9 + static CTypeResult is_ctl(char c); // ASCII 0-31,127 (includes ws) + static CTypeResult is_hex(char c); // 0-9,A-F,a-f + static CTypeResult is_ws(char c); // SP,HT + static CTypeResult is_cr(char c); // CR + static CTypeResult is_lf(char c); // LF + static CTypeResult is_spcr(char c); // SP,CR + static CTypeResult is_splf(char c); // SP,LF + static CTypeResult is_wslfcr(char c); // SP,HT,LF,CR + static CTypeResult is_tspecials(char c); // HTTP chars that need quoting + static CTypeResult is_token(char c); // token (not CTL or specials) + static CTypeResult is_extra(char c); // !,*,QUOT,(,),COMMA + static CTypeResult is_safe(char c); // [$-_.+] + static CTypeResult is_unsafe(char c); // SP,DBLQUOT,#,%,<,> + static CTypeResult is_national(char c); // {,},|,BACKSLASH,^,~,[,],` + static CTypeResult is_reserved(char c); // :,/,?,:,@,&,= + static CTypeResult is_unreserved(char c); // alpha,digit,safe,extra,nat. + static CTypeResult is_punct(char c); // !"#$%&'()*+,-./:;<>=?@_{}|~ + static CTypeResult is_end_of_url(char c); // NUL,CR,SP + static CTypeResult is_eow(char c); // NUL,CR,LF + static CTypeResult is_wildmat(char c); // \,*,?,[ + static CTypeResult is_sep(char c); // NULL,COMMA,':','!',wslfcr + static CTypeResult is_empty(char c); // wslfcr,# + static CTypeResult is_alnum(char c); // 0-9,A-Z,a-z + static CTypeResult is_space(char c); // ' ' HT,VT,NP,CR,LF + static CTypeResult is_control(char c); // 0-31 127 + static CTypeResult is_mime_sep(char c); // ()<>,;\"/[]?{} \t + static CTypeResult is_http_field_name(char c); // not : or mime_sep except for @ + static CTypeResult is_http_field_value(char c); // not CR, LF, comma, or " ////////////////// // string tests // ////////////////// - static CTypeResult is_escape(const char *seq); // %<hex><hex> - static CTypeResult is_uchar(const char *seq); // starts unresrvd or is escape - static CTypeResult is_pchar(const char *seq); // uchar,:,@,&,=,+ (see code) + static CTypeResult is_escape(const char *seq); // %<hex><hex> + static CTypeResult is_uchar(const char *seq); // starts unresrvd or is escape + static CTypeResult is_pchar(const char *seq); // uchar,:,@,&,=,+ (see code) /////////////////// // unimplemented // /////////////////// - //static CTypeResult is_comment(const char * str); - //static CTypeResult is_ctext(const char * str); + // static CTypeResult is_comment(const char * str); + // static CTypeResult is_ctext(const char * str); //////////////// // operations // @@ -166,8 +165,8 @@ public: static unsigned char *scan_while(unsigned char *ptr, unsigned int n, uint32_t bitmask); private: - ParseRules(const ParseRules &); - ParseRules & operator =(const ParseRules &); + ParseRules(const ParseRules &); + ParseRules &operator=(const ParseRules &); }; /* * * * * * * * * * * * * * * * * * * * * * * * * * * * @@ -177,14 +176,14 @@ private: inline CTypeResult ParseRules::is_type(char c, uint32_t bitmask) { - return (parseRulesCType[(unsigned char) c] & bitmask); + return (parseRulesCType[(unsigned char)c] & bitmask); } inline CTypeResult ParseRules::is_char(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char) c] & is_char_BIT); + return (parseRulesCType[(unsigned char)c] & is_char_BIT); #else return ((c & 0x80) == 0); #endif @@ -194,7 +193,7 @@ inline CTypeResult ParseRules::is_upalpha(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char) c] & is_upalpha_BIT); + return (parseRulesCType[(unsigned char)c] & is_upalpha_BIT); #else return (c >= 'A' && c <= 'Z'); #endif @@ -204,7 +203,7 @@ inline CTypeResult ParseRules::is_loalpha(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char) c] & is_loalpha_BIT); + return (parseRulesCType[(unsigned char)c] & is_loalpha_BIT); #else return (c >= 'a' && c <= 'z'); #endif @@ -214,7 +213,7 @@ inline CTypeResult ParseRules::is_alpha(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char) c] & is_alpha_BIT); + return (parseRulesCType[(unsigned char)c] & is_alpha_BIT); #else return (is_upalpha(c) || is_loalpha(c)); #endif @@ -224,7 +223,7 @@ inline CTypeResult ParseRules::is_digit(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char) c] & is_digit_BIT); + return (parseRulesCType[(unsigned char)c] & is_digit_BIT); #else return (c >= '0' && c <= '9'); #endif @@ -234,7 +233,7 @@ inline CTypeResult ParseRules::is_alnum(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char) c] & is_alnum_BIT); + return (parseRulesCType[(unsigned char)c] & is_alnum_BIT); #else return (is_alpha(c) || is_digit(c)); #endif @@ -244,7 +243,7 @@ inline CTypeResult ParseRules::is_ctl(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char) c] & is_ctl_BIT); + return (parseRulesCType[(unsigned char)c] & is_ctl_BIT); #else return ((!(c & 0x80) && c <= 31) || c == 127); #endif @@ -254,7 +253,7 @@ inline CTypeResult ParseRules::is_ws(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char) c] & is_ws_BIT); + return (parseRulesCType[(unsigned char)c] & is_ws_BIT); #else return (c == CHAR_SP || c == CHAR_HT); #endif @@ -264,7 +263,7 @@ inline CTypeResult ParseRules::is_hex(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char) c] & is_hex_BIT); + return (parseRulesCType[(unsigned char)c] & is_hex_BIT); #else return ((c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f') || (c >= '0' && c <= '9')); #endif @@ -286,7 +285,7 @@ inline CTypeResult ParseRules::is_splf(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char) c] & is_splf_BIT); + return (parseRulesCType[(unsigned char)c] & is_splf_BIT); #else return (c == CHAR_SP || c == CHAR_LF); #endif @@ -296,7 +295,7 @@ inline CTypeResult ParseRules::is_spcr(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char) c] & is_spcr_BIT); + return (parseRulesCType[(unsigned char)c] & is_spcr_BIT); #else return (c == CHAR_SP || c == CHAR_CR); #endif @@ -306,7 +305,7 @@ inline CTypeResult ParseRules::is_wslfcr(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char) c] & is_wslfcr_BIT); + return (parseRulesCType[(unsigned char)c] & is_wslfcr_BIT); #else return ParseRules::is_ws(c) || ParseRules::is_splf(c) || ParseRules::is_spcr(c); #endif @@ -316,7 +315,7 @@ inline CTypeResult ParseRules::is_extra(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char) c] & is_extra_BIT); + return (parseRulesCType[(unsigned char)c] & is_extra_BIT); #else switch (c) { case '!': @@ -335,7 +334,7 @@ inline CTypeResult ParseRules::is_safe(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char) c] & is_safe_BIT); + return (parseRulesCType[(unsigned char)c] & is_safe_BIT); #else return (c == '$' || c == '-' || c == '_' || c == '.' || c == '+'); #endif @@ -345,7 +344,7 @@ inline CTypeResult ParseRules::is_unsafe(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char) c] & is_unsafe_BIT); + return (parseRulesCType[(unsigned char)c] & is_unsafe_BIT); #else if (is_ctl(c)) return (true); @@ -367,7 +366,7 @@ inline CTypeResult ParseRules::is_reserved(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char) c] & is_reserved_BIT); + return (parseRulesCType[(unsigned char)c] & is_reserved_BIT); #else switch (c) { case ';': @@ -387,7 +386,7 @@ inline CTypeResult ParseRules::is_national(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char) c] & is_national_BIT); + return (parseRulesCType[(unsigned char)c] & is_national_BIT); #else switch (c) { case '{': @@ -409,7 +408,7 @@ inline CTypeResult ParseRules::is_unreserved(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char) c] & is_unreserved_BIT); + return (parseRulesCType[(unsigned char)c] & is_unreserved_BIT); #else return (is_alpha(c) || is_digit(c) || is_safe(c) || is_extra(c) || is_national(c)); #endif @@ -419,7 +418,7 @@ inline CTypeResult ParseRules::is_punct(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char) c] & is_punct_BIT); + return (parseRulesCType[(unsigned char)c] & is_punct_BIT); #else switch (c) { case '!': @@ -463,10 +462,9 @@ inline CTypeResult ParseRules::is_end_of_url(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char) c] & is_end_of_url_BIT); + return (parseRulesCType[(unsigned char)c] & is_end_of_url_BIT); #else - return (c == '\0' || c == '\n' || c == ' ' || ParseRules::is_ctl(c) - ); + return (c == '\0' || c == '\n' || c == ' ' || ParseRules::is_ctl(c)); #endif } @@ -513,7 +511,7 @@ inline CTypeResult ParseRules::is_tspecials(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char) c] & is_tspecials_BIT); + return (parseRulesCType[(unsigned char)c] & is_tspecials_BIT); #else switch (c) { case '(': @@ -545,7 +543,7 @@ inline CTypeResult ParseRules::is_token(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char) c] & is_token_BIT); + return (parseRulesCType[(unsigned char)c] & is_token_BIT); #else return (is_char(c) && !(is_ctl(c) || is_tspecials(c))); #endif @@ -555,7 +553,7 @@ inline char ParseRules::ink_toupper(char c) { #ifndef COMPILE_PARSE_RULES - return parseRulesCTypeToUpper[(unsigned char) c]; + return parseRulesCTypeToUpper[(unsigned char)c]; #else int up_case = c; const int up_case_diff = 'a' - 'A'; @@ -571,7 +569,7 @@ inline char ParseRules::ink_tolower(char c) { #ifndef COMPILE_PARSE_RULES - return parseRulesCTypeToLower[(unsigned char) c]; + return parseRulesCTypeToLower[(unsigned char)c]; #else int lo_case = c; const int lo_case_diff = 'a' - 'A'; @@ -587,7 +585,7 @@ inline CTypeResult ParseRules::is_eow(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char) c] & is_eow_BIT); + return (parseRulesCType[(unsigned char)c] & is_eow_BIT); #else return (c == '\0' || c == '\r' || c == '\n'); #endif @@ -597,7 +595,7 @@ inline CTypeResult ParseRules::is_wildmat(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char) c] & is_wildmat_BIT); + return (parseRulesCType[(unsigned char)c] & is_wildmat_BIT); #else return (c == '*' || c == '?' || c == '[' || c == '\\'); #endif @@ -607,7 +605,7 @@ inline CTypeResult ParseRules::is_sep(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char) c] & is_sep_BIT); + return (parseRulesCType[(unsigned char)c] & is_sep_BIT); #else return (!c || c == ',' || c == ':' || c == '!' || is_wslfcr(c)); #endif @@ -617,7 +615,7 @@ inline CTypeResult ParseRules::is_empty(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char) c] & is_empty_BIT); + return (parseRulesCType[(unsigned char)c] & is_empty_BIT); #else return (c == '#' || is_wslfcr(c)); #endif @@ -627,7 +625,7 @@ inline CTypeResult ParseRules::is_space(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char) c] & is_space_BIT); + return (parseRulesCType[(unsigned char)c] & is_space_BIT); #else switch (c) { case CHAR_SP: @@ -646,9 +644,9 @@ inline CTypeResult ParseRules::is_control(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char) c] & is_control_BIT); + return (parseRulesCType[(unsigned char)c] & is_control_BIT); #else - if (((unsigned char) c) < 32 || ((unsigned char) c) == 127) + if (((unsigned char)c) < 32 || ((unsigned char)c) == 127) return true; return false; #endif @@ -658,11 +656,10 @@ inline CTypeResult ParseRules::is_mime_sep(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char) c] & is_mime_sep_BIT); + return (parseRulesCType[(unsigned char)c] & is_mime_sep_BIT); #else - if ((c == '(') || (c == ')') || (c == '<') || (c == '>') || (c == '@') || - (c == ',') || (c == ';') || (c == '\\') || (c == '\"') || - (c == '/') || (c == '[') || (c == ']') || (c == '?') || (c == '{') || (c == '}') || (c == ' ') || (c == '\t')) + if ((c == '(') || (c == ')') || (c == '<') || (c == '>') || (c == '@') || (c == ',') || (c == ';') || (c == '\\') || + (c == '\"') || (c == '/') || (c == '[') || (c == ']') || (c == '?') || (c == '{') || (c == '}') || (c == ' ') || (c == '\t')) return true; return false; #endif @@ -672,7 +669,7 @@ inline CTypeResult ParseRules::is_http_field_name(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char) c] & is_http_field_name_BIT); + return (parseRulesCType[(unsigned char)c] & is_http_field_name_BIT); #else if ((c == ':') || (is_mime_sep(c) && (c != '@'))) return false; @@ -684,7 +681,7 @@ inline CTypeResult ParseRules::is_http_field_value(char c) { #ifndef COMPILE_PARSE_RULES - return (CTypeResult) (parseRulesCType[(unsigned char) c] & is_http_field_value_BIT); + return (CTypeResult)(parseRulesCType[(unsigned char)c] & is_http_field_value_BIT); #else switch (c) { case CHAR_CR: @@ -770,7 +767,7 @@ ParseRules::strcasestr(const char *s1, const char *s2) for (i1 = 0; s1[i1] != '\0'; i1++) if (ink_tolower(s1[i1]) == ink_tolower(s2[0])) - if (strncasecmp_eow(&s1[i1], &s2[0], (int) s2_len)) + if (strncasecmp_eow(&s1[i1], &s2[0], (int)s2_len)) return (&s1[i1]); return (0); @@ -798,9 +795,9 @@ static inline int ink_get_hex(char c) { if (ParseRules::is_digit(c)) - return (int) (c - '0'); + return (int)(c - '0'); c = ParseRules::ink_tolower(c); - return (int) ((c - 'a') + 10); + return (int)((c - 'a') + 10); } int64_t ink_atoi64(const char *);
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/ts/Ptr.h ---------------------------------------------------------------------- diff --git a/lib/ts/Ptr.h b/lib/ts/Ptr.h index 7cea36c..9c5fa0d 100644 --- a/lib/ts/Ptr.h +++ b/lib/ts/Ptr.h @@ -32,7 +32,7 @@ ****************************************************************************/ -#if !defined (_Ptr_h_) +#if !defined(_Ptr_h_) #define _Ptr_h_ #include "ink_atomic.h" @@ -46,20 +46,16 @@ class NonAtomicRefCountObj { public: - NonAtomicRefCountObj():m_refcount(0) + NonAtomicRefCountObj() : m_refcount(0) { return; } + NonAtomicRefCountObj(const NonAtomicRefCountObj &s) : m_refcount(0) { + (void)s; return; } - NonAtomicRefCountObj(const NonAtomicRefCountObj & s):m_refcount(0) + virtual ~NonAtomicRefCountObj() { return; } + NonAtomicRefCountObj &operator=(const NonAtomicRefCountObj &s) { - (void) s; - return; - } - virtual ~ NonAtomicRefCountObj() { - return; - } - NonAtomicRefCountObj & operator =(const NonAtomicRefCountObj & s) { - (void) s; + (void)s; return (*this); } @@ -67,7 +63,8 @@ public: int refcount_dec(); int refcount() const; - virtual void free() + virtual void + free() { delete this; } @@ -98,63 +95,45 @@ NonAtomicRefCountObj::refcount() const } - //////////////////////////////////////////////////////////////////////// // // class NonAtomicPtr // //////////////////////////////////////////////////////////////////////// -template<class T> class NonAtomicPtr { +template <class T> class NonAtomicPtr +{ public: - explicit NonAtomicPtr(T * ptr = 0); + explicit NonAtomicPtr(T *ptr = 0); NonAtomicPtr(const NonAtomicPtr<T> &); ~NonAtomicPtr(); - NonAtomicPtr<T> &operator =(const NonAtomicPtr<T> &); - NonAtomicPtr<T> &operator =(T *); + NonAtomicPtr<T> &operator=(const NonAtomicPtr<T> &); + NonAtomicPtr<T> &operator=(T *); void clear(); - operator T *() const - { - return (m_ptr); - } - T *operator ->() const - { - return (m_ptr); - } - T & operator *() const - { - return (*m_ptr); - } + operator T *() const { return (m_ptr); } + T *operator->() const { return (m_ptr); } + T &operator*() const { return (*m_ptr); } - int operator ==(const T * p) - { - return (m_ptr == p); - } - int operator ==(const NonAtomicPtr<T> &p) - { - return (m_ptr == p.m_ptr); - } - int operator !=(const T * p) - { - return (m_ptr != p); - } - int operator !=(const NonAtomicPtr<T> &p) - { - return (m_ptr != p.m_ptr); - } + int operator==(const T *p) { return (m_ptr == p); } + int operator==(const NonAtomicPtr<T> &p) { return (m_ptr == p.m_ptr); } + int operator!=(const T *p) { return (m_ptr != p); } + int operator!=(const NonAtomicPtr<T> &p) { return (m_ptr != p.m_ptr); } - NonAtomicRefCountObj *_ptr() + NonAtomicRefCountObj * + _ptr() { - return (NonAtomicRefCountObj *) m_ptr; + return (NonAtomicRefCountObj *)m_ptr; } T *m_ptr; }; template <typename T> -NonAtomicPtr<T> make_nonatomic_ptr(T * p) { +NonAtomicPtr<T> +make_nonatomic_ptr(T *p) +{ return NonAtomicPtr<T>(p); } @@ -163,25 +142,21 @@ NonAtomicPtr<T> make_nonatomic_ptr(T * p) { // inline functions definitions // //////////////////////////////////////////////////////////////////////// -template<class T> inline NonAtomicPtr<T>::NonAtomicPtr(T * ptr /* = 0 */ ) -: -m_ptr(ptr) +template <class T> inline NonAtomicPtr<T>::NonAtomicPtr(T *ptr /* = 0 */) : m_ptr(ptr) { if (m_ptr) _ptr()->refcount_inc(); return; } -template<class T> inline NonAtomicPtr<T>::NonAtomicPtr(const NonAtomicPtr<T> &src) -: -m_ptr(src.m_ptr) +template <class T> inline NonAtomicPtr<T>::NonAtomicPtr(const NonAtomicPtr<T> &src) : m_ptr(src.m_ptr) { if (m_ptr) _ptr()->refcount_inc(); return; } -template<class T> inline NonAtomicPtr<T>::~NonAtomicPtr() +template <class T> inline NonAtomicPtr<T>::~NonAtomicPtr() { if ((m_ptr) && _ptr()->refcount_dec() == 0) { _ptr()->free(); @@ -189,7 +164,7 @@ template<class T> inline NonAtomicPtr<T>::~NonAtomicPtr() return; } -template<class T> inline NonAtomicPtr<T> &NonAtomicPtr<T>::operator =(T * p) +template <class T> inline NonAtomicPtr<T> &NonAtomicPtr<T>::operator=(T *p) { T *temp_ptr = m_ptr; @@ -202,23 +177,25 @@ template<class T> inline NonAtomicPtr<T> &NonAtomicPtr<T>::operator =(T * p) _ptr()->refcount_inc(); } - if ((temp_ptr) && ((NonAtomicRefCountObj *) temp_ptr)->refcount_dec() == 0) { - ((NonAtomicRefCountObj *) temp_ptr)->free(); + if ((temp_ptr) && ((NonAtomicRefCountObj *)temp_ptr)->refcount_dec() == 0) { + ((NonAtomicRefCountObj *)temp_ptr)->free(); } return (*this); } -template<class T> inline void NonAtomicPtr<T>::clear() +template <class T> +inline void +NonAtomicPtr<T>::clear() { if (m_ptr) { - if (!((NonAtomicRefCountObj *) m_ptr)->refcount_dec()) - ((NonAtomicRefCountObj *) m_ptr)->free(); + if (!((NonAtomicRefCountObj *)m_ptr)->refcount_dec()) + ((NonAtomicRefCountObj *)m_ptr)->free(); m_ptr = NULL; } } -template<class T> inline NonAtomicPtr<T> &NonAtomicPtr<T>::operator =(const NonAtomicPtr<T> &src) +template <class T> inline NonAtomicPtr<T> &NonAtomicPtr<T>::operator=(const NonAtomicPtr<T> &src) { - return (operator =(src.m_ptr)); + return (operator=(src.m_ptr)); } @@ -228,11 +205,8 @@ template<class T> inline NonAtomicPtr<T> &NonAtomicPtr<T>::operator =(const NonA //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// -struct ForceVFPTToTop -{ - virtual ~ ForceVFPTToTop() - { - } +struct ForceVFPTToTop { + virtual ~ForceVFPTToTop() {} }; @@ -242,21 +216,19 @@ struct ForceVFPTToTop // prototypical class for reference counting // //////////////////////////////////////////////////////////////////////// -class RefCountObj: public ForceVFPTToTop +class RefCountObj : public ForceVFPTToTop { public: - RefCountObj():m_refcount(0) - { - } - RefCountObj(const RefCountObj & s):m_refcount(0) + RefCountObj() : m_refcount(0) {} + RefCountObj(const RefCountObj &s) : m_refcount(0) { - (void) s; + (void)s; return; } - virtual ~ RefCountObj() { - } - RefCountObj & operator =(const RefCountObj & s) { - (void) s; + virtual ~RefCountObj() {} + RefCountObj &operator=(const RefCountObj &s) + { + (void)s; return (*this); } @@ -264,7 +236,8 @@ public: int refcount_dec(); int refcount() const; - virtual void free() + virtual void + free() { delete this; } @@ -276,7 +249,7 @@ public: inline int RefCountObj::refcount_inc() { - return ink_atomic_increment((int *) &m_refcount, 1) + 1; + return ink_atomic_increment((int *)&m_refcount, 1) + 1; } #define REF_COUNT_OBJ_REFCOUNT_INC(_x) (_x)->refcount_inc() @@ -285,7 +258,7 @@ RefCountObj::refcount_inc() inline int RefCountObj::refcount_dec() { - return ink_atomic_increment((int *) &m_refcount, -1) - 1; + return ink_atomic_increment((int *)&m_refcount, -1) - 1; } #define REF_COUNT_OBJ_REFCOUNT_DEC(_x) (_x)->refcount_dec() @@ -302,65 +275,50 @@ RefCountObj::refcount() const // class Ptr // //////////////////////////////////////////////////////////////////////// -template<class T> class Ptr { +template <class T> class Ptr +{ public: - explicit Ptr(T * p = 0); + explicit Ptr(T *p = 0); Ptr(const Ptr<T> &); ~Ptr(); void clear(); - Ptr<T> &operator =(const Ptr<T> &); - Ptr<T> &operator =(T *); + Ptr<T> &operator=(const Ptr<T> &); + Ptr<T> &operator=(T *); - T * to_ptr() { + T * + to_ptr() + { if (m_ptr && m_ptr->m_refcount == 1) { - T * ptr = m_ptr; + T *ptr = m_ptr; m_ptr = 0; ptr->m_refcount = 0; return ptr; } return 0; } - operator T *() const - { - return (m_ptr); - } - T *operator ->() const - { - return (m_ptr); - } - T & operator *() const - { - return (*m_ptr); - } + operator T *() const { return (m_ptr); } + T *operator->() const { return (m_ptr); } + T &operator*() const { return (*m_ptr); } - int operator ==(const T * p) - { - return (m_ptr == p); - } - int operator ==(const Ptr<T> &p) - { - return (m_ptr == p.m_ptr); - } - int operator !=(const T * p) - { - return (m_ptr != p); - } - int operator !=(const Ptr<T> &p) - { - return (m_ptr != p.m_ptr); - } + int operator==(const T *p) { return (m_ptr == p); } + int operator==(const Ptr<T> &p) { return (m_ptr == p.m_ptr); } + int operator!=(const T *p) { return (m_ptr != p); } + int operator!=(const Ptr<T> &p) { return (m_ptr != p.m_ptr); } - RefCountObj *_ptr() + RefCountObj * + _ptr() { - return (RefCountObj *) m_ptr; + return (RefCountObj *)m_ptr; } T *m_ptr; }; template <typename T> -Ptr<T> make_ptr(T * p) { +Ptr<T> +make_ptr(T *p) +{ return Ptr<T>(p); } @@ -369,25 +327,21 @@ Ptr<T> make_ptr(T * p) { // inline functions definitions // //////////////////////////////////////////////////////////////////////// -template<class T> inline Ptr<T>::Ptr(T * ptr /* = 0 */ ) -: -m_ptr(ptr) +template <class T> inline Ptr<T>::Ptr(T *ptr /* = 0 */) : m_ptr(ptr) { if (m_ptr) _ptr()->refcount_inc(); return; } -template<class T> inline Ptr<T>::Ptr(const Ptr<T> &src) -: -m_ptr(src.m_ptr) +template <class T> inline Ptr<T>::Ptr(const Ptr<T> &src) : m_ptr(src.m_ptr) { if (m_ptr) _ptr()->refcount_inc(); return; } -template<class T> inline Ptr<T>::~Ptr() +template <class T> inline Ptr<T>::~Ptr() { if ((m_ptr) && _ptr()->refcount_dec() == 0) { _ptr()->free(); @@ -395,7 +349,7 @@ template<class T> inline Ptr<T>::~Ptr() return; } -template<class T> inline Ptr<T> &Ptr<T>::operator =(T * p) +template <class T> inline Ptr<T> &Ptr<T>::operator=(T *p) { T *temp_ptr = m_ptr; @@ -408,23 +362,25 @@ template<class T> inline Ptr<T> &Ptr<T>::operator =(T * p) _ptr()->refcount_inc(); } - if ((temp_ptr) && ((RefCountObj *) temp_ptr)->refcount_dec() == 0) { - ((RefCountObj *) temp_ptr)->free(); + if ((temp_ptr) && ((RefCountObj *)temp_ptr)->refcount_dec() == 0) { + ((RefCountObj *)temp_ptr)->free(); } return (*this); } -template<class T> inline void Ptr<T>::clear() +template <class T> +inline void +Ptr<T>::clear() { if (m_ptr) { - if (!((RefCountObj *) m_ptr)->refcount_dec()) - ((RefCountObj *) m_ptr)->free(); + if (!((RefCountObj *)m_ptr)->refcount_dec()) + ((RefCountObj *)m_ptr)->free(); m_ptr = NULL; } } -template<class T> inline Ptr<T> &Ptr<T>::operator =(const Ptr<T> &src) +template <class T> inline Ptr<T> &Ptr<T>::operator=(const Ptr<T> &src) { - return (operator =(src.m_ptr)); + return (operator=(src.m_ptr)); } #endif http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/ts/RawHashTable.cc ---------------------------------------------------------------------- diff --git a/lib/ts/RawHashTable.cc b/lib/ts/RawHashTable.cc index 8c86e79..192a4fa 100644 --- a/lib/ts/RawHashTable.cc +++ b/lib/ts/RawHashTable.cc @@ -29,4 +29,3 @@ */ #include "RawHashTable.h" - http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/ts/RawHashTable.h ---------------------------------------------------------------------- diff --git a/lib/ts/RawHashTable.h b/lib/ts/RawHashTable.h index 529f724..7d19701 100644 --- a/lib/ts/RawHashTable.h +++ b/lib/ts/RawHashTable.h @@ -29,7 +29,7 @@ */ #ifndef _RawHashTable_h_ -#define _RawHashTable_h_ +#define _RawHashTable_h_ #include "libts.h" @@ -41,8 +41,7 @@ // ////////////////////////////////////////////////////////////////////////////// -typedef enum -{ +typedef enum { RawHashTable_KeyType_String = InkHashTableKeyType_String, RawHashTable_KeyType_Word = InkHashTableKeyType_Word } RawHashTable_KeyType; @@ -61,19 +60,19 @@ typedef InkHashTableIteratorState RawHashTable_IteratorState; class RawHashTable { private: - InkHashTable * ht; + InkHashTable *ht; RawHashTable_KeyType key_type; bool deallocate_values_on_destruct; public: - inkcoreapi RawHashTable(RawHashTable_KeyType key_type, bool deallocate_values_on_destruct = false); - virtual ~ RawHashTable(); + inkcoreapi RawHashTable(RawHashTable_KeyType key_type, bool deallocate_values_on_destruct = false); + virtual ~RawHashTable(); // // these are the simplest accessor functions // - bool getValue(RawHashTable_Key key, RawHashTable_Value * value_ptr); + bool getValue(RawHashTable_Key key, RawHashTable_Value *value_ptr); void setValue(RawHashTable_Key key, RawHashTable_Value value_ptr); bool isBound(RawHashTable_Key key); bool unbindKey(RawHashTable_Key key); @@ -84,18 +83,18 @@ public: // RawHashTable_Binding *getCurrentBinding(RawHashTable_Key key); - RawHashTable_Binding *getOrCreateBinding(RawHashTable_Key key, bool * was_new = NULL); + RawHashTable_Binding *getOrCreateBinding(RawHashTable_Key key, bool *was_new = NULL); - void setBindingValue(RawHashTable_Binding * binding, RawHashTable_Value value); - RawHashTable_Key getKeyFromBinding(RawHashTable_Binding * binding); - RawHashTable_Value getValueFromBinding(RawHashTable_Binding * binding); + void setBindingValue(RawHashTable_Binding *binding, RawHashTable_Value value); + RawHashTable_Key getKeyFromBinding(RawHashTable_Binding *binding); + RawHashTable_Value getValueFromBinding(RawHashTable_Binding *binding); // // these functions allow you to iterate through RawHashTable bindings // - RawHashTable_Binding *firstBinding(RawHashTable_IteratorState * state_ptr); - RawHashTable_Binding *nextBinding(RawHashTable_IteratorState * state_ptr); + RawHashTable_Binding *firstBinding(RawHashTable_IteratorState *state_ptr); + RawHashTable_Binding *nextBinding(RawHashTable_IteratorState *state_ptr); }; ////////////////////////////////////////////////////////////////////////////// @@ -111,11 +110,11 @@ public: */ inline bool -RawHashTable::getValue(RawHashTable_Key key, RawHashTable_Value * value_ptr) +RawHashTable::getValue(RawHashTable_Key key, RawHashTable_Value *value_ptr) { int is_bound; - is_bound = ink_hash_table_lookup(ht, (InkHashTableKey) key, (InkHashTableValue *) value_ptr); + is_bound = ink_hash_table_lookup(ht, (InkHashTableKey)key, (InkHashTableValue *)value_ptr); return (is_bound ? true : false); } @@ -132,7 +131,7 @@ RawHashTable::getValue(RawHashTable_Key key, RawHashTable_Value * value_ptr) inline void RawHashTable::setValue(RawHashTable_Key key, RawHashTable_Value value) { - ink_hash_table_insert(ht, (InkHashTableKey) key, (InkHashTableValue) value); + ink_hash_table_insert(ht, (InkHashTableKey)key, (InkHashTableValue)value); } /** @@ -148,7 +147,7 @@ RawHashTable::setValue(RawHashTable_Key key, RawHashTable_Value value) inline bool RawHashTable::isBound(RawHashTable_Key key) { - int status = ink_hash_table_isbound(ht, (InkHashTableKey) key); + int status = ink_hash_table_isbound(ht, (InkHashTableKey)key); return (status ? true : false); } @@ -166,7 +165,7 @@ RawHashTable::unbindKey(RawHashTable_Key key) { int status; - status = ink_hash_table_delete(ht, (InkHashTableKey) key); + status = ink_hash_table_delete(ht, (InkHashTableKey)key); return (status ? true : false); } @@ -180,10 +179,10 @@ RawHashTable::unbindKey(RawHashTable_Key key) inline void RawHashTable::replaceString(char *key, char *string) { -// if (key_type != RawHashTable_KeyType_String) -// { -// throw BadKeyType(); -// } + // if (key_type != RawHashTable_KeyType_String) + // { + // throw BadKeyType(); + // } ink_hash_table_replace_string(ht, key, string); } @@ -199,8 +198,8 @@ RawHashTable::getCurrentBinding(RawHashTable_Key key) { InkHashTableEntry *he_ptr; - he_ptr = ink_hash_table_lookup_entry(ht, (InkHashTableKey) key); - return ((RawHashTable_Binding *) he_ptr); + he_ptr = ink_hash_table_lookup_entry(ht, (InkHashTableKey)key); + return ((RawHashTable_Binding *)he_ptr); } /** @@ -214,14 +213,14 @@ RawHashTable::getCurrentBinding(RawHashTable_Key key) */ inline RawHashTable_Binding * -RawHashTable::getOrCreateBinding(RawHashTable_Key key, bool * was_new) +RawHashTable::getOrCreateBinding(RawHashTable_Key key, bool *was_new) { int _was_new; InkHashTableEntry *he_ptr; - he_ptr = ink_hash_table_get_entry(ht, (InkHashTableKey) key, &_was_new); + he_ptr = ink_hash_table_get_entry(ht, (InkHashTableKey)key, &_was_new); *was_new = (_was_new ? true : false); - return ((RawHashTable_Binding *) he_ptr); + return ((RawHashTable_Binding *)he_ptr); } /** @@ -235,9 +234,9 @@ RawHashTable::getOrCreateBinding(RawHashTable_Key key, bool * was_new) */ inline void -RawHashTable::setBindingValue(RawHashTable_Binding * binding, RawHashTable_Value value) +RawHashTable::setBindingValue(RawHashTable_Binding *binding, RawHashTable_Value value) { - ink_hash_table_set_entry(ht, (InkHashTableEntry *) binding, (InkHashTableValue) value); + ink_hash_table_set_entry(ht, (InkHashTableEntry *)binding, (InkHashTableValue)value); } /** @@ -245,12 +244,12 @@ RawHashTable::setBindingValue(RawHashTable_Binding * binding, RawHashTable_Value */ inline RawHashTable_Key -RawHashTable::getKeyFromBinding(RawHashTable_Binding * binding) +RawHashTable::getKeyFromBinding(RawHashTable_Binding *binding) { InkHashTableKey ht_key; - ht_key = ink_hash_table_entry_key(ht, (InkHashTableEntry *) binding); - return ((RawHashTable_Key) ht_key); + ht_key = ink_hash_table_entry_key(ht, (InkHashTableEntry *)binding); + return ((RawHashTable_Key)ht_key); } /** @@ -258,12 +257,12 @@ RawHashTable::getKeyFromBinding(RawHashTable_Binding * binding) */ inline RawHashTable_Value -RawHashTable::getValueFromBinding(RawHashTable_Binding * binding) +RawHashTable::getValueFromBinding(RawHashTable_Binding *binding) { InkHashTableValue ht_value; - ht_value = ink_hash_table_entry_value(ht, (InkHashTableEntry *) binding); - return ((RawHashTable_Value) ht_value); + ht_value = ink_hash_table_entry_value(ht, (InkHashTableEntry *)binding); + return ((RawHashTable_Value)ht_value); } /** @@ -273,25 +272,22 @@ RawHashTable::getValueFromBinding(RawHashTable_Binding * binding) */ inline RawHashTable_Binding * -RawHashTable::firstBinding(RawHashTable_IteratorState * state_ptr) +RawHashTable::firstBinding(RawHashTable_IteratorState *state_ptr) { InkHashTableEntry *he_ptr; - he_ptr = ink_hash_table_iterator_first(ht, (InkHashTableIteratorState *) state_ptr); - return ((RawHashTable_Binding *) he_ptr); + he_ptr = ink_hash_table_iterator_first(ht, (InkHashTableIteratorState *)state_ptr); + return ((RawHashTable_Binding *)he_ptr); } -inline -RawHashTable::RawHashTable(RawHashTable_KeyType akey_type, bool adeallocate_values_on_destruct) +inline RawHashTable::RawHashTable(RawHashTable_KeyType akey_type, bool adeallocate_values_on_destruct) { RawHashTable::key_type = akey_type; RawHashTable::deallocate_values_on_destruct = adeallocate_values_on_destruct; - ht = ink_hash_table_create((InkHashTableKeyType) key_type); + ht = ink_hash_table_create((InkHashTableKeyType)key_type); } -inline -RawHashTable::~ -RawHashTable() +inline RawHashTable::~RawHashTable() { if (deallocate_values_on_destruct) ink_hash_table_destroy_and_free_values(ht); @@ -306,12 +302,12 @@ RawHashTable() */ inline RawHashTable_Binding * -RawHashTable::nextBinding(RawHashTable_IteratorState * state_ptr) +RawHashTable::nextBinding(RawHashTable_IteratorState *state_ptr) { InkHashTableEntry *he_ptr; - he_ptr = ink_hash_table_iterator_next(ht, (InkHashTableIteratorState *) state_ptr); - return ((RawHashTable_Binding *) he_ptr); + he_ptr = ink_hash_table_iterator_next(ht, (InkHashTableIteratorState *)state_ptr); + return ((RawHashTable_Binding *)he_ptr); } ////////////////////////////////////////////////////////////////////////////// @@ -323,19 +319,19 @@ RawHashTable::nextBinding(RawHashTable_IteratorState * state_ptr) class RawHashTableIter { public: - RawHashTableIter(RawHashTable & ht); + RawHashTableIter(RawHashTable &ht); ~RawHashTableIter(); - RawHashTable_Value & operator ++(); // get next - RawHashTable_Value & operator () () const; // get current - operator const void *() const; // is valid + RawHashTable_Value &operator++(); // get next + RawHashTable_Value &operator()() const; // get current + operator const void *() const; // is valid - RawHashTable_Value & value() const; // get current value - const char *key() const; // get current key + RawHashTable_Value &value() const; // get current value + const char *key() const; // get current key private: - RawHashTable & m_ht; + RawHashTable &m_ht; RawHashTable_Binding *m_currentBinding; RawHashTable_IteratorState m_hashIterState; }; @@ -346,29 +342,23 @@ private: // ////////////////////////////////////////////////////////////////////////////// -inline RawHashTable_Value & -RawHashTableIter::operator () () -const +inline RawHashTable_Value &RawHashTableIter::operator()() const { return (m_currentBinding->clientData); } -inline RawHashTable_Value & -RawHashTableIter::operator ++() +inline RawHashTable_Value &RawHashTableIter::operator++() { m_currentBinding = m_ht.nextBinding(&m_hashIterState); return (m_currentBinding->clientData); } -inline -RawHashTableIter::operator const void *() -const +inline RawHashTableIter::operator const void *() const { return ((m_currentBinding != 0) ? this : 0); } -inline - RawHashTable_Value & +inline RawHashTable_Value & RawHashTableIter::value() const { return (m_currentBinding->clientData); @@ -380,19 +370,13 @@ RawHashTableIter::key() const return (m_currentBinding->key.string); } -inline -RawHashTableIter::RawHashTableIter(RawHashTable & ht) - : -m_ht(ht), -m_currentBinding(0) +inline RawHashTableIter::RawHashTableIter(RawHashTable &ht) : m_ht(ht), m_currentBinding(0) { m_currentBinding = m_ht.firstBinding(&m_hashIterState); return; } -inline -RawHashTableIter::~ -RawHashTableIter() +inline RawHashTableIter::~RawHashTableIter() { return; } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/ts/RbTree.cc ---------------------------------------------------------------------- diff --git a/lib/ts/RbTree.cc b/lib/ts/RbTree.cc index ba7d2a0..64b80fa 100644 --- a/lib/ts/RbTree.cc +++ b/lib/ts/RbTree.cc @@ -21,296 +21,300 @@ #include "RbTree.h" -namespace ts { namespace detail { - -/// Equality. -/// @note If @a n is @c NULL it is treated as having the color @c BLACK. -/// @return @c true if @a c and the color of @a n are the same. -inline bool operator == ( RBNode* n, RBNode::Color c ) { - return c == ( n ? n->getColor() : RBNode::BLACK); -} -/// Equality. -/// @note If @a n is @c NULL it is treated as having the color @c BLACK. -/// @return @c true if @a c and the color of @a n are the same. -inline bool operator == ( RBNode::Color c, RBNode* n ) { - return n == c; -} - -RBNode* -RBNode::getChild(Direction d) const { - return d == RIGHT ? _right - : d == LEFT ? _left - : 0 - ; -} +namespace ts +{ +namespace detail +{ + /// Equality. + /// @note If @a n is @c NULL it is treated as having the color @c BLACK. + /// @return @c true if @a c and the color of @a n are the same. + inline bool operator==(RBNode *n, RBNode::Color c) { return c == (n ? n->getColor() : RBNode::BLACK); } + /// Equality. + /// @note If @a n is @c NULL it is treated as having the color @c BLACK. + /// @return @c true if @a c and the color of @a n are the same. + inline bool operator==(RBNode::Color c, RBNode *n) { return n == c; } + + RBNode * + RBNode::getChild(Direction d) const + { + return d == RIGHT ? _right : d == LEFT ? _left : 0; + } -RBNode* -RBNode::rotate(Direction d) { - self* parent = _parent; // Cache because it can change before we use it. - Direction child_dir = _parent ? _parent->getChildDirection(this) : NONE; - Direction other_dir = this->flip(d); - self* child = this; - - if (d != NONE && this->getChild(other_dir)) { - child = this->getChild(other_dir); - this->clearChild(other_dir); - this->setChild(child->getChild(d), other_dir); - child->clearChild(d); - child->setChild(this, d); - child->structureFixup(); - this->structureFixup(); - if (parent) { - parent->clearChild(child_dir); - parent->setChild(child, child_dir); - } else { - child->_parent = 0; + RBNode * + RBNode::rotate(Direction d) + { + self *parent = _parent; // Cache because it can change before we use it. + Direction child_dir = _parent ? _parent->getChildDirection(this) : NONE; + Direction other_dir = this->flip(d); + self *child = this; + + if (d != NONE && this->getChild(other_dir)) { + child = this->getChild(other_dir); + this->clearChild(other_dir); + this->setChild(child->getChild(d), other_dir); + child->clearChild(d); + child->setChild(this, d); + child->structureFixup(); + this->structureFixup(); + if (parent) { + parent->clearChild(child_dir); + parent->setChild(child, child_dir); + } else { + child->_parent = 0; + } } + return child; } - return child; -} - -RBNode* -RBNode::setChild(self* n, Direction d) { - if (n) n->_parent = this; - if (d == RIGHT) _right = n; - else if (d == LEFT) _left = n; - return n; -} -// Returns the root node -RBNode* -RBNode::rippleStructureFixup() { - self* root = this; // last node seen, root node at the end - self* p = this; - while (p) { - p->structureFixup(); - root = p; - p = root->_parent; + RBNode * + RBNode::setChild(self *n, Direction d) + { + if (n) + n->_parent = this; + if (d == RIGHT) + _right = n; + else if (d == LEFT) + _left = n; + return n; } - return root; -} -void -RBNode::replaceWith(self* n) { - n->_color = _color; - if (_parent) { - Direction d = _parent->getChildDirection(this); - _parent->setChild(0, d); - if (_parent != n) _parent->setChild(n, d); - } else { - n->_parent = 0; + // Returns the root node + RBNode * + RBNode::rippleStructureFixup() + { + self *root = this; // last node seen, root node at the end + self *p = this; + while (p) { + p->structureFixup(); + root = p; + p = root->_parent; + } + return root; } - n->_left = n->_right = 0; - if (_left && _left != n) n->setChild(_left, LEFT); - if (_right && _right != n) n->setChild(_right, RIGHT); - _left = _right = 0; -} -/* Rebalance the tree. This node is the unbalanced node. */ -RBNode* -RBNode::rebalanceAfterInsert() { - self* x(this); // the node with the imbalance - - while (x && x->_parent == RED) { - Direction child_dir = NONE; - - if (x->_parent->_parent) - child_dir = x->_parent->_parent->getChildDirection(x->_parent); - else - break; - Direction other_dir(flip(child_dir)); - - self* y = x->_parent->_parent->getChild(other_dir); - if (y == RED) { - x->_parent->_color = BLACK; - y->_color = BLACK; - x = x->_parent->_parent; - x->_color = RED; + void + RBNode::replaceWith(self *n) + { + n->_color = _color; + if (_parent) { + Direction d = _parent->getChildDirection(this); + _parent->setChild(0, d); + if (_parent != n) + _parent->setChild(n, d); } else { - if (x->_parent->getChild(other_dir) == x) { - x = x->_parent; - x->rotate(child_dir); - } - // Note setting the parent color to BLACK causes the loop to exit. - x->_parent->_color = BLACK; - x->_parent->_parent->_color = RED; - x->_parent->_parent->rotate(other_dir); + n->_parent = 0; } + n->_left = n->_right = 0; + if (_left && _left != n) + n->setChild(_left, LEFT); + if (_right && _right != n) + n->setChild(_right, RIGHT); + _left = _right = 0; } - // every node above this one has a subtree structure change, - // so notify it. serendipitously, this makes it easy to return - // the new root node. - self* root = this->rippleStructureFixup(); - root->_color = BLACK; + /* Rebalance the tree. This node is the unbalanced node. */ + RBNode * + RBNode::rebalanceAfterInsert() + { + self *x(this); // the node with the imbalance - return root; -} + while (x && x->_parent == RED) { + Direction child_dir = NONE; + if (x->_parent->_parent) + child_dir = x->_parent->_parent->getChildDirection(x->_parent); + else + break; + Direction other_dir(flip(child_dir)); + + self *y = x->_parent->_parent->getChild(other_dir); + if (y == RED) { + x->_parent->_color = BLACK; + y->_color = BLACK; + x = x->_parent->_parent; + x->_color = RED; + } else { + if (x->_parent->getChild(other_dir) == x) { + x = x->_parent; + x->rotate(child_dir); + } + // Note setting the parent color to BLACK causes the loop to exit. + x->_parent->_color = BLACK; + x->_parent->_parent->_color = RED; + x->_parent->_parent->rotate(other_dir); + } + } + + // every node above this one has a subtree structure change, + // so notify it. serendipitously, this makes it easy to return + // the new root node. + self *root = this->rippleStructureFixup(); + root->_color = BLACK; -// Returns new root node -RBNode* -RBNode::remove() { - self* root = 0; // new root node, returned to caller - - /* Handle two special cases first. - - This is the only node in the tree, return a new root of NIL - - This is the root node with only one child, return that child as new root - */ - if (!_parent && !(_left && _right)) { - if (_left) { - _left->_parent = 0; - root = _left; - root->_color = BLACK; - } else if (_right) { - _right->_parent = 0; - root = _right; - root->_color = BLACK; - } // else that was the only node, so leave @a root @c NULL. return root; } - /* The node to be removed from the tree. - If @c this (the target node) has both children, we remove - its successor, which cannot have a left child and - put that node in place of the target node. Otherwise this - node has at most one child, so we can remove it. - Note that the successor of a node with a right child is always - a right descendant of the node. Therefore, remove_node - is an element of the tree rooted at this node. - Because of the initial special case checks, we know - that remove_node is @b not the root node. - */ - self* remove_node(_left && _right ? _right->leftmostDescendant() : this); - - // This is the color of the node physically removed from the tree. - // Normally this is the color of @a remove_node - Color remove_color = remove_node->_color; - // Need to remember the direction from @a remove_node to @a splice_node - Direction d(NONE); - - // The child node that will be promoted to replace the removed node. - // The choice of left or right is irrelevant, as remove_node has at - // most one child (and splice_node may be NIL if remove_node has no - // children). - self* splice_node(remove_node->_left - ? remove_node->_left - : remove_node->_right - ); - - if (splice_node) { - // @c replace_with copies color so in this case the actual color - // lost is that of the splice_node. - remove_color = splice_node->_color; - remove_node->replaceWith(splice_node); - } else { - // No children on remove node so we can just clip it off the tree - // We update splice_node to maintain the invariant that it is - // the node where the physical removal occurred. - splice_node = remove_node->_parent; - // Keep @a d up to date. - d = splice_node->getChildDirection(remove_node); - splice_node->setChild(0, d); - } - // If the node to pull out of the tree isn't this one, - // then replace this node in the tree with that removed - // node in liu of copying the data over. - if (remove_node != this) { - // Don't leave @a splice_node referring to a removed node - if (splice_node == this) splice_node = remove_node; - this->replaceWith(remove_node); - } + // Returns new root node + RBNode * + RBNode::remove() + { + self *root = 0; // new root node, returned to caller - root = splice_node->rebalanceAfterRemove(remove_color, d); - root->_color = BLACK; - return root; -} + /* Handle two special cases first. + - This is the only node in the tree, return a new root of NIL + - This is the root node with only one child, return that child as new root + */ + if (!_parent && !(_left && _right)) { + if (_left) { + _left->_parent = 0; + root = _left; + root->_color = BLACK; + } else if (_right) { + _right->_parent = 0; + root = _right; + root->_color = BLACK; + } // else that was the only node, so leave @a root @c NULL. + return root; + } -/** - * Rebalance tree after a deletion - * Called on the spliced in node or its parent, whichever is not NIL. - * This modifies the tree structure only if @a c is @c BLACK. - */ -RBNode* -RBNode::rebalanceAfterRemove( - Color c, //!< The color of the removed node - Direction d //!< Direction of removed node from its parent -) { - self* root; - - if (BLACK == c) { // only rebalance if too much black - self* n = this; - self* parent = n->_parent; - - // If @a direction is set, then we need to start at a leaf psuedo-node. - // This is why we need @a parent, otherwise we could just use @a n. - if (NONE != d) { - parent = n; - n = 0; + /* The node to be removed from the tree. + If @c this (the target node) has both children, we remove + its successor, which cannot have a left child and + put that node in place of the target node. Otherwise this + node has at most one child, so we can remove it. + Note that the successor of a node with a right child is always + a right descendant of the node. Therefore, remove_node + is an element of the tree rooted at this node. + Because of the initial special case checks, we know + that remove_node is @b not the root node. + */ + self *remove_node(_left && _right ? _right->leftmostDescendant() : this); + + // This is the color of the node physically removed from the tree. + // Normally this is the color of @a remove_node + Color remove_color = remove_node->_color; + // Need to remember the direction from @a remove_node to @a splice_node + Direction d(NONE); + + // The child node that will be promoted to replace the removed node. + // The choice of left or right is irrelevant, as remove_node has at + // most one child (and splice_node may be NIL if remove_node has no + // children). + self *splice_node(remove_node->_left ? remove_node->_left : remove_node->_right); + + if (splice_node) { + // @c replace_with copies color so in this case the actual color + // lost is that of the splice_node. + remove_color = splice_node->_color; + remove_node->replaceWith(splice_node); + } else { + // No children on remove node so we can just clip it off the tree + // We update splice_node to maintain the invariant that it is + // the node where the physical removal occurred. + splice_node = remove_node->_parent; + // Keep @a d up to date. + d = splice_node->getChildDirection(remove_node); + splice_node->setChild(0, d); } - while (parent) { // @a n is not the root - // If the current node is RED, we can just recolor and be done - if (n == RED) { - n->_color = BLACK; - break; - } else { - // Parameterizing the rebalance logic on the directions. We - // write for the left child case and flip directions for the - // right child case - Direction near(LEFT), far(RIGHT); - if ( - (NONE == d && parent->getChildDirection(n) == RIGHT) - || RIGHT == d - ) { - near = RIGHT; - far = LEFT; - } + // If the node to pull out of the tree isn't this one, + // then replace this node in the tree with that removed + // node in liu of copying the data over. + if (remove_node != this) { + // Don't leave @a splice_node referring to a removed node + if (splice_node == this) + splice_node = remove_node; + this->replaceWith(remove_node); + } - self* w = parent->getChild(far); // sibling(n) + root = splice_node->rebalanceAfterRemove(remove_color, d); + root->_color = BLACK; + return root; + } - if (w->_color == RED) { - w->_color = BLACK; - parent->_color = RED; - parent->rotate(near); - w = parent->getChild(far); - } + /** + * Rebalance tree after a deletion + * Called on the spliced in node or its parent, whichever is not NIL. + * This modifies the tree structure only if @a c is @c BLACK. + */ + RBNode * + RBNode::rebalanceAfterRemove(Color c, //!< The color of the removed node + Direction d //!< Direction of removed node from its parent + ) + { + self *root; + + if (BLACK == c) { // only rebalance if too much black + self *n = this; + self *parent = n->_parent; + + // If @a direction is set, then we need to start at a leaf psuedo-node. + // This is why we need @a parent, otherwise we could just use @a n. + if (NONE != d) { + parent = n; + n = 0; + } - self* wfc = w->getChild(far); - if (w->getChild(near) == BLACK && wfc == BLACK) { - w->_color = RED; - n = parent; - parent = n->_parent; - d = NONE; // Cancel any leaf node logic + while (parent) { // @a n is not the root + // If the current node is RED, we can just recolor and be done + if (n == RED) { + n->_color = BLACK; + break; } else { - if (wfc->_color == BLACK) { - w->getChild(near)->_color = BLACK; - w->_color = RED; - w->rotate(far); + // Parameterizing the rebalance logic on the directions. We + // write for the left child case and flip directions for the + // right child case + Direction near(LEFT), far(RIGHT); + if ((NONE == d && parent->getChildDirection(n) == RIGHT) || RIGHT == d) { + near = RIGHT; + far = LEFT; + } + + self *w = parent->getChild(far); // sibling(n) + + if (w->_color == RED) { + w->_color = BLACK; + parent->_color = RED; + parent->rotate(near); w = parent->getChild(far); - wfc = w->getChild(far); // w changed, update far child cache. } - w->_color = parent->_color; - parent->_color = BLACK; - wfc->_color = BLACK; - parent->rotate(near); - break; + + self *wfc = w->getChild(far); + if (w->getChild(near) == BLACK && wfc == BLACK) { + w->_color = RED; + n = parent; + parent = n->_parent; + d = NONE; // Cancel any leaf node logic + } else { + if (wfc->_color == BLACK) { + w->getChild(near)->_color = BLACK; + w->_color = RED; + w->rotate(far); + w = parent->getChild(far); + wfc = w->getChild(far); // w changed, update far child cache. + } + w->_color = parent->_color; + parent->_color = BLACK; + wfc->_color = BLACK; + parent->rotate(near); + break; + } } } } + root = this->rippleStructureFixup(); + return root; } - root = this->rippleStructureFixup(); - return root; -} -/** Ensure that the local information associated with each node is - correct globally This should only be called on debug builds as it - breaks any efficiencies we have gained from our tree structure. - */ -int -RBNode::validate() { -# if 0 + /** Ensure that the local information associated with each node is + correct globally This should only be called on debug builds as it + breaks any efficiencies we have gained from our tree structure. + */ + int + RBNode::validate() + { +#if 0 int black_ht = 0; int black_ht1, black_ht2; @@ -344,12 +348,9 @@ RBNode::validate() { black_ht = 0; return black_ht; -# else - return 0; -# endif +#else + return 0; +#endif + } +} } - -}} - - - http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/ts/RbTree.h ---------------------------------------------------------------------- diff --git a/lib/ts/RbTree.h b/lib/ts/RbTree.h index 5c8ac43..03635e7 100644 --- a/lib/ts/RbTree.h +++ b/lib/ts/RbTree.h @@ -22,179 +22,200 @@ #ifndef RBTREE_H_ #define RBTREE_H_ -namespace ts { namespace detail { - -/** A node in a red/black tree. - - This class provides only the basic tree operations. The client - must provide the search and decision logic. This enables this - class to be a base class for templated nodes with much less code - duplication. -*/ -struct RBNode { - typedef RBNode self; ///< self reference type - - /// Node colors - typedef enum { RED, BLACK } Color; - - /// Directional constants - typedef enum { NONE, LEFT, RIGHT } Direction; - - /// Get a child by direction. - /// @return The child in the direction @a d if it exists, - /// @c NULL if not. - self* getChild( - Direction d //!< The direction of the desired child - ) const; - - /** Determine which child a node is - @return @c LEFT if @a n is the left child, - @c RIGHT if @a n is the right child, - @c NONE if @a n is not a child +namespace ts +{ +namespace detail +{ + /** A node in a red/black tree. + + This class provides only the basic tree operations. The client + must provide the search and decision logic. This enables this + class to be a base class for templated nodes with much less code + duplication. */ - Direction getChildDirection( - self* const& n //!< The presumed child node - ) const { - return (n == _left) ? LEFT : (n == _right) ? RIGHT : NONE; - } - - /** Get the parent node. - @return A Node* to the parent node or a @c nil Node* if no parent. - */ - self* getParent() const { return const_cast<self*>(_parent); } - - /// @return The color of the node. - Color getColor() const { return _color; } - - self* leftmostDescendant() const { - const self* n = this; + struct RBNode { + typedef RBNode self; ///< self reference type + + /// Node colors + typedef enum { + RED, + BLACK, + } Color; + + /// Directional constants + typedef enum { + NONE, + LEFT, + RIGHT, + } Direction; + + /// Get a child by direction. + /// @return The child in the direction @a d if it exists, + /// @c NULL if not. + self *getChild(Direction d //!< The direction of the desired child + ) const; + + /** Determine which child a node is + @return @c LEFT if @a n is the left child, + @c RIGHT if @a n is the right child, + @c NONE if @a n is not a child + */ + Direction + getChildDirection(self *const &n //!< The presumed child node + ) const + { + return (n == _left) ? LEFT : (n == _right) ? RIGHT : NONE; + } + + /** Get the parent node. + @return A Node* to the parent node or a @c nil Node* if no parent. + */ + self * + getParent() const + { + return const_cast<self *>(_parent); + } + + /// @return The color of the node. + Color + getColor() const + { + return _color; + } + + self * + leftmostDescendant() const + { + const self *n = this; while (n->_left) - n = n->_left; - - return const_cast<self*>(n); - } - - /** Reverse a direction - @return @c LEFT if @a d is @c RIGHT, @c RIGHT if @a d is @c LEFT, - @c NONE otherwise. - */ - Direction flip(Direction d) { - return LEFT == d ? RIGHT : RIGHT == d ? LEFT : NONE; - } - - /** Perform internal validation checks. - @return 0 on failure, black height of the tree on success. - */ - int validate(); - - /// Default constructor. - RBNode() - : _color(RED) - , _parent(0) - , _left(0) - , _right(0) - , _next(0) - , _prev(0) { - } - - /// Destructor (force virtual). - virtual ~RBNode() { } - - /** Rotate the subtree rooted at this node. - The node is rotated in to the position of one of its children. - Which child is determined by the direction parameter @a d. The - child in the other direction becomes the new root of the subtree. - - If the parent pointer is set, then the child pointer of the original - parent is updated so that the tree is left in a consistent state. - - @note If there is no child in the other direction, the rotation - fails and the original node is returned. It is @b not required - that a child exist in the direction specified by @a d. - - @return The new root node for the subtree. - */ - self* rotate( - Direction d //!< The direction to rotate - ); - - /** Set the child node in direction @a d to @a n. - The @a d child is set to the node @a n. The pointers in this - node and @a n are set correctly. This can only be called if - there is no child node already present. - - @return @a n. - */ - self* setChild( - self* n, //!< The node to set as the child - Direction d //!< The direction of the child - ); - - /** Remove this node from the tree. - The tree is rebalanced after removal. - @return The new root node. - */ - self* remove(); - - void clearChild(Direction dir) { - if (LEFT == dir) _left = 0; - else if (RIGHT == dir) _right = 0; - } - - /** @name Subclass hook methods */ - //@{ - /** Structural change notification. - This method is called if the structure of the subtree rooted at - this node was changed. - - This is intended a hook. The base method is empty so that subclasses - are not required to override. - */ - virtual void structureFixup() {} - - /** Called from @c validate to perform any additional validation checks. - Clients should chain this if they wish to perform additional checks. - @return @c true if the validation is successful, @c false otherwise. - @note The base method simply returns @c true. - */ - virtual bool structureValidate() { return true; } - //@} - - /** Replace this node with another node. - This is presumed to be non-order modifying so the next reference - is @b not updated. - */ - void replaceWith( - self* n //!< Node to put in place of this node. - ); - - //! Rebalance the tree starting at this node - /** The tree is rebalanced so that all of the invariants are - true. The (potentially new) root of the tree is returned. - - @return The root node of the tree after the rebalance. - */ - self* rebalanceAfterInsert(); - - /** Rebalance the tree after a deletion. - Called on the lowest modified node. - @return The new root of the tree. - */ - self* rebalanceAfterRemove( - Color c, //!< The color of the removed node. - Direction d //!< Direction of removed node from parent - ); - - //! Invoke @c structure_fixup() on this node and all of its ancestors. - self* rippleStructureFixup(); - - Color _color; ///< node color - self* _parent; ///< parent node (needed for rotations) - self* _left; ///< left child - self* _right; ///< right child - self* _next; ///< Next node. - self* _prev; ///< Previous node. -}; + n = n->_left; + + return const_cast<self *>(n); + } + + /** Reverse a direction + @return @c LEFT if @a d is @c RIGHT, @c RIGHT if @a d is @c LEFT, + @c NONE otherwise. + */ + Direction + flip(Direction d) + { + return LEFT == d ? RIGHT : RIGHT == d ? LEFT : NONE; + } + + /** Perform internal validation checks. + @return 0 on failure, black height of the tree on success. + */ + int validate(); + + /// Default constructor. + RBNode() : _color(RED), _parent(0), _left(0), _right(0), _next(0), _prev(0) {} + + /// Destructor (force virtual). + virtual ~RBNode() {} + + /** Rotate the subtree rooted at this node. + The node is rotated in to the position of one of its children. + Which child is determined by the direction parameter @a d. The + child in the other direction becomes the new root of the subtree. + + If the parent pointer is set, then the child pointer of the original + parent is updated so that the tree is left in a consistent state. + + @note If there is no child in the other direction, the rotation + fails and the original node is returned. It is @b not required + that a child exist in the direction specified by @a d. + + @return The new root node for the subtree. + */ + self *rotate(Direction d //!< The direction to rotate + ); + + /** Set the child node in direction @a d to @a n. + The @a d child is set to the node @a n. The pointers in this + node and @a n are set correctly. This can only be called if + there is no child node already present. + + @return @a n. + */ + self *setChild(self *n, //!< The node to set as the child + Direction d //!< The direction of the child + ); + + /** Remove this node from the tree. + The tree is rebalanced after removal. + @return The new root node. + */ + self *remove(); + + void + clearChild(Direction dir) + { + if (LEFT == dir) + _left = 0; + else if (RIGHT == dir) + _right = 0; + } + + /** @name Subclass hook methods */ + //@{ + /** Structural change notification. + This method is called if the structure of the subtree rooted at + this node was changed. + + This is intended a hook. The base method is empty so that subclasses + are not required to override. + */ + virtual void + structureFixup() + { + } + + /** Called from @c validate to perform any additional validation checks. + Clients should chain this if they wish to perform additional checks. + @return @c true if the validation is successful, @c false otherwise. + @note The base method simply returns @c true. + */ + virtual bool + structureValidate() + { + return true; + } + //@} + + /** Replace this node with another node. + This is presumed to be non-order modifying so the next reference + is @b not updated. + */ + void replaceWith(self *n //!< Node to put in place of this node. + ); + + //! Rebalance the tree starting at this node + /** The tree is rebalanced so that all of the invariants are + true. The (potentially new) root of the tree is returned. + + @return The root node of the tree after the rebalance. + */ + self *rebalanceAfterInsert(); + + /** Rebalance the tree after a deletion. + Called on the lowest modified node. + @return The new root of the tree. + */ + self *rebalanceAfterRemove(Color c, //!< The color of the removed node. + Direction d //!< Direction of removed node from parent + ); + + //! Invoke @c structure_fixup() on this node and all of its ancestors. + self *rippleStructureFixup(); + + Color _color; ///< node color + self *_parent; ///< parent node (needed for rotations) + self *_left; ///< left child + self *_right; ///< right child + self *_next; ///< Next node. + self *_prev; ///< Previous node. + }; } /* namespace detail */ http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/ts/Regex.cc ---------------------------------------------------------------------- diff --git a/lib/ts/Regex.cc b/lib/ts/Regex.cc index ba98608..ecccb86 100644 --- a/lib/ts/Regex.cc +++ b/lib/ts/Regex.cc @@ -25,11 +25,8 @@ #include "Regex.h" #ifdef PCRE_CONFIG_JIT -struct RegexThreadKey -{ - RegexThreadKey() { - ink_thread_key_create(&this->key, (void (*)(void *)) &pcre_jit_stack_free); - } +struct RegexThreadKey { + RegexThreadKey() { ink_thread_key_create(&this->key, (void (*)(void *)) & pcre_jit_stack_free); } ink_thread_key key; }; @@ -41,7 +38,7 @@ get_jit_stack(void *data ATS_UNUSED) { pcre_jit_stack *jit_stack; - if ((jit_stack = (pcre_jit_stack *) ink_thread_getspecific(k.key)) == NULL) { + if ((jit_stack = (pcre_jit_stack *)ink_thread_getspecific(k.key)) == NULL) { jit_stack = pcre_jit_stack_alloc(ats_pagesize(), 1024 * 1024); // 1 page min and 1MB max ink_thread_setspecific(k.key, (void *)jit_stack); } @@ -82,8 +79,8 @@ Regex::compile(const char *pattern, unsigned flags) regex_extra = pcre_study(regex, study_opts, &error); #ifdef PCRE_CONFIG_JIT - if (regex_extra) - pcre_assign_jit_stack(regex_extra, &get_jit_stack, NULL); + if (regex_extra) + pcre_assign_jit_stack(regex_extra, &get_jit_stack, NULL); #endif return true; @@ -100,7 +97,7 @@ Regex::exec(const char *str, int length) { int ovector[30], rv; - rv = pcre_exec(regex, regex_extra, str, length , 0, 0, ovector, countof(ovector)); + rv = pcre_exec(regex, regex_extra, str, length, 0, 0, ovector, countof(ovector)); return rv > 0 ? true : false; } @@ -118,13 +115,13 @@ Regex::~Regex() DFA::~DFA() { - dfa_pattern * p = _my_patterns; - dfa_pattern * t; + dfa_pattern *p = _my_patterns; + dfa_pattern *t; - while(p) { + while (p) { if (p->_re) delete p->_re; - if(p->_p) + if (p->_p) ats_free(p->_p); t = p->_next; ats_free(p); @@ -135,14 +132,14 @@ DFA::~DFA() dfa_pattern * DFA::build(const char *pattern, unsigned flags) { - dfa_pattern* ret; + dfa_pattern *ret; int rv; if (!(flags & RE_UNANCHORED)) { flags |= RE_ANCHORED; } - ret = (dfa_pattern*)ats_malloc(sizeof(dfa_pattern)); + ret = (dfa_pattern *)ats_malloc(sizeof(dfa_pattern)); ret->_p = NULL; ret->_re = new Regex(); @@ -159,9 +156,11 @@ DFA::build(const char *pattern, unsigned flags) return ret; } -int DFA::compile(const char *pattern, unsigned flags) { +int +DFA::compile(const char *pattern, unsigned flags) +{ ink_assert(_my_patterns == NULL); - _my_patterns = build(pattern,flags); + _my_patterns = build(pattern, flags); if (_my_patterns) return 0; else @@ -178,7 +177,7 @@ DFA::compile(const char **patterns, int npatterns, unsigned flags) for (i = 0; i < npatterns; i++) { pattern = patterns[i]; - ret = build(pattern,flags); + ret = build(pattern, flags); if (!ret) { continue; } @@ -187,16 +186,14 @@ DFA::compile(const char **patterns, int npatterns, unsigned flags) _my_patterns = ret; _my_patterns->_next = NULL; _my_patterns->_idx = i; - } - else { + } else { end = _my_patterns; - while( end->_next ) { + while (end->_next) { end = end->_next; } - end->_next = ret; //add to end + end->_next = ret; // add to end ret->_idx = i; } - } return 0; @@ -205,16 +202,16 @@ DFA::compile(const char **patterns, int npatterns, unsigned flags) int DFA::match(const char *str) const { - return match(str,strlen(str)); + return match(str, strlen(str)); } int DFA::match(const char *str, int length) const { int rc; - dfa_pattern * p = _my_patterns; + dfa_pattern *p = _my_patterns; - while(p) { + while (p) { rc = p->_re->exec(str, length); if (rc > 0) { return p->_idx; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/ts/Regex.h ---------------------------------------------------------------------- diff --git a/lib/ts/Regex.h b/lib/ts/Regex.h index ac45958..f56e855 100644 --- a/lib/ts/Regex.h +++ b/lib/ts/Regex.h @@ -32,8 +32,7 @@ #include <pcre.h> #endif -enum REFlags -{ +enum REFlags { RE_CASE_INSENSITIVE = 0x0001, // default is case sensitive RE_UNANCHORED = 0x0002, // default (for DFA) is to anchor at the first matching position RE_ANCHORED = 0x0004, // default (for Regex) is unanchored @@ -42,8 +41,7 @@ enum REFlags class Regex { public: - Regex():regex(NULL), regex_extra(NULL) { - } + Regex() : regex(NULL), regex_extra(NULL) {} bool compile(const char *pattern, unsigned flags = 0); // It is safe to call exec() concurrently on the same object instance bool exec(const char *str); @@ -59,14 +57,13 @@ typedef struct __pat { int _idx; Regex *_re; char *_p; - __pat * _next; + __pat *_next; } dfa_pattern; class DFA { public: - DFA():_my_patterns(0) { - } + DFA() : _my_patterns(0) {} ~DFA(); @@ -77,9 +74,9 @@ public: int match(const char *str, int length) const; private: - dfa_pattern * build(const char *pattern, unsigned flags = 0); + dfa_pattern *build(const char *pattern, unsigned flags = 0); - dfa_pattern * _my_patterns; + dfa_pattern *_my_patterns; }; #endif /* __TS_REGEX_H__ */ http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/ts/Regression.cc ---------------------------------------------------------------------- diff --git a/lib/ts/Regression.cc b/lib/ts/Regression.cc index 39e7438..e64632c 100644 --- a/lib/ts/Regression.cc +++ b/lib/ts/Regression.cc @@ -43,12 +43,13 @@ int RegressionTest::final_status = REGRESSION_TEST_PASSED; char * regression_status_string(int status) { - return (char *) (status == REGRESSION_TEST_NOT_RUN ? "NOT_RUN" : - (status == REGRESSION_TEST_PASSED ? "PASSED" : - (status == REGRESSION_TEST_INPROGRESS ? "INPROGRESS" : "FAILED"))); + return ( + char *)(status == REGRESSION_TEST_NOT_RUN ? + "NOT_RUN" : + (status == REGRESSION_TEST_PASSED ? "PASSED" : (status == REGRESSION_TEST_INPROGRESS ? "INPROGRESS" : "FAILED"))); } -RegressionTest::RegressionTest(const char *name_arg, TestFunction * function_arg, int aopt) +RegressionTest::RegressionTest(const char *name_arg, TestFunction *function_arg, int aopt) { name = name_arg; function = function_arg; @@ -68,16 +69,16 @@ RegressionTest::RegressionTest(const char *name_arg, TestFunction * function_arg } static inline int -start_test(RegressionTest * t) +start_test(RegressionTest *t) { ink_assert(t->status == REGRESSION_TEST_NOT_RUN); t->status = REGRESSION_TEST_INPROGRESS; fprintf(stderr, "REGRESSION TEST %s started\n", t->name); - (*t->function) (t, regression_level, &t->status); + (*t->function)(t, regression_level, &t->status); int tresult = t->status; if (tresult != REGRESSION_TEST_INPROGRESS) { - fprintf(stderr, " REGRESSION_RESULT %s:%*s %s\n", t->name, - 40 - (int)strlen(t->name), " ", regression_status_string(tresult)); + fprintf(stderr, " REGRESSION_RESULT %s:%*s %s\n", t->name, 40 - (int)strlen(t->name), " ", + regression_status_string(tresult)); t->printed = 1; } return tresult; @@ -92,7 +93,7 @@ RegressionTest::run(char *atest) dfa.compile(".*"); fprintf(stderr, "REGRESSION_TEST initialization begun\n"); // start the non exclusive tests - for (RegressionTest * t = test; t; t = t->next) { + for (RegressionTest *t = test; t; t = t->next) { if ((dfa.match(t->name) >= 0)) { int res = start_test(t); if (res == REGRESSION_TEST_FAILED) @@ -106,15 +107,14 @@ RegressionTest::run(char *atest) int RegressionTest::run_some() { - if (current) { if (current->status == REGRESSION_TEST_INPROGRESS) return REGRESSION_TEST_INPROGRESS; else if (current->status != REGRESSION_TEST_NOT_RUN) { if (!current->printed) { current->printed = true; - fprintf(stderr, " REGRESSION_RESULT %s:%*s %s\n", current->name, - 40 - (int)strlen(current->name), " ", regression_status_string(current->status)); + fprintf(stderr, " REGRESSION_RESULT %s:%*s %s\n", current->name, 40 - (int)strlen(current->name), " ", + regression_status_string(current->status)); } current = current->next; } @@ -148,8 +148,8 @@ check_test_list: while (t) { if ((t->status == REGRESSION_TEST_PASSED || t->status == REGRESSION_TEST_FAILED) && !t->printed) { t->printed = true; - fprintf(stderr, " REGRESSION_RESULT %s:%*s %s\n", t->name, - 40 - (int)strlen(t->name), " ", regression_status_string(t->status)); + fprintf(stderr, " REGRESSION_RESULT %s:%*s %s\n", t->name, 40 - (int)strlen(t->name), " ", + regression_status_string(t->status)); } switch (t->status) { @@ -202,9 +202,10 @@ rperf(RegressionTest *t, const char *tag, double val) return (l); } -REGRESSION_TEST(Regression) (RegressionTest * t, int atype, int *status) { - (void) t; - (void) atype; +REGRESSION_TEST(Regression)(RegressionTest *t, int atype, int *status) +{ + (void)t; + (void)atype; rprintf(t, "regression test\n"); rperf(t, "speed", 100.0); if (!test) http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/ts/Regression.h ---------------------------------------------------------------------- diff --git a/lib/ts/Regression.h b/lib/ts/Regression.h index 189abe5..ef0f5c7 100644 --- a/lib/ts/Regression.h +++ b/lib/ts/Regression.h @@ -45,28 +45,27 @@ // status values -#define REGRESSION_TEST_PASSED 1 -#define REGRESSION_TEST_INPROGRESS 0 // initial value -#define REGRESSION_TEST_FAILED -1 -#define REGRESSION_TEST_NOT_RUN -2 +#define REGRESSION_TEST_PASSED 1 +#define REGRESSION_TEST_INPROGRESS 0 // initial value +#define REGRESSION_TEST_FAILED -1 +#define REGRESSION_TEST_NOT_RUN -2 // regression types -#define REGRESSION_TEST_NONE 0 -#define REGRESSION_TEST_QUICK 1 -#define REGRESSION_TEST_NIGHTLY 2 -#define REGRESSION_TEST_EXTENDED 3 - // use only for testing TS error handling! -#define REGRESSION_TEST_FATAL 4 +#define REGRESSION_TEST_NONE 0 +#define REGRESSION_TEST_QUICK 1 +#define REGRESSION_TEST_NIGHTLY 2 +#define REGRESSION_TEST_EXTENDED 3 +// use only for testing TS error handling! +#define REGRESSION_TEST_FATAL 4 // regression options -#define REGRESSION_OPT_EXCLUSIVE (1 << 0) +#define REGRESSION_OPT_EXCLUSIVE (1 << 0) struct RegressionTest; -typedef void TestFunction(RegressionTest * t, int type, int *status); +typedef void TestFunction(RegressionTest *t, int type, int *status); -struct RegressionTest -{ +struct RegressionTest { const char *name; TestFunction *function; RegressionTest *next; @@ -74,7 +73,7 @@ struct RegressionTest int printed; int opt; - RegressionTest(const char *name_arg, TestFunction * function_arg, int aopt); + RegressionTest(const char *name_arg, TestFunction *function_arg, int aopt); static int final_status; static int ran_tests; @@ -85,17 +84,17 @@ struct RegressionTest static int check_status(); }; -#define REGRESSION_TEST(_f) \ -void RegressionTest_##_f(RegressionTest * t, int atype, int *pstatus); \ -RegressionTest regressionTest_##_f(#_f,&RegressionTest_##_f, 0);\ -void RegressionTest_##_f +#define REGRESSION_TEST(_f) \ + void RegressionTest_##_f(RegressionTest *t, int atype, int *pstatus); \ + RegressionTest regressionTest_##_f(#_f, &RegressionTest_##_f, 0); \ + void RegressionTest_##_f -#define EXCLUSIVE_REGRESSION_TEST(_f) \ -void RegressionTest_##_f(RegressionTest * t, int atype, int *pstatus); \ -RegressionTest regressionTest_##_f(#_f,&RegressionTest_##_f, REGRESSION_OPT_EXCLUSIVE);\ -void RegressionTest_##_f +#define EXCLUSIVE_REGRESSION_TEST(_f) \ + void RegressionTest_##_f(RegressionTest *t, int atype, int *pstatus); \ + RegressionTest regressionTest_##_f(#_f, &RegressionTest_##_f, REGRESSION_OPT_EXCLUSIVE); \ + void RegressionTest_##_f -int rprintf(RegressionTest * t, const char *format, ...); +int rprintf(RegressionTest *t, const char *format, ...); int rperf(RegressionTest *t, const char *tag, double val); char *regression_status_string(int status);
