/* * * This file and its contents are the property of The MathWorks, Inc. * * This file contains confidential proprietary information. * The reproduction, distribution, utilization or the communication * of this file or any part thereof is strictly prohibited. * Offenders will be held liable for the payment of damages. * * Copyright 1999-2012 The MathWorks, Inc. * */ /* * Polyspace internal header : * definition/implemetation of char_traits, char_traits * * Norm restriction : * - some typedef do not refer to real type (off_type, pos_type, state_type) * - random return for : * + compare * + find * + not_eof * - unspecified behaviour for eq_int_type is specified * * Side effects : * try to include stdio.h/wchar.h to get EOF, WEOF, wint_t * if PST_HAS_STDIO_H/PST_HAS_WCHAR_H is defined * if after include, EOF, WEOF or wint_t is not defined, define it with "defaults" value * * Remarks : * As for the moment we do not use it, the implementation * is quite precise * * */ #ifndef __polyspace__char_traits_h #define __polyspace__char_traits_h // for streamoff #include <__polyspace__typedefs.h> // include to have mbstate_t and WEOF #include <__polyspace__wchar.h> // include to have EOF #include <__polyspace__stdio.h> // include to have CHAR_MIN and CHAR_MAX #include <__polyspace__limits.h> // Macros undefined at the end #define PST_CHECK_PRECONDITION(c) assert(c) #define PST_CHECK_IN_VALID_RANGE(e, l, h) assert((l<=e) && (e<=h)) #define PST_STRING_IS_VALID_RANGE(charT, ptr, n) \ { for( size_t i=0; i::state_type> streampos // typedef fpos::state_type> wstreampos template class fpos; typedef fpos streampos ; typedef fpos wstreampos ; // Interface template struct char_traits { typedef charT char_type; typedef charT int_type; typedef streampos pos_type; typedef streamoff off_type; typedef mbstate_t state_type; static int_type eof() { volatile int_type random = 0; return random; } static int_type to_int_type(const char_type& c) { volatile int_type random = 0; return random; } static void assign(charT& dst, const charT& src) { dst = src; } static __ps_bool eq(const charT& left, const charT& right) { return left == right; } static __ps_bool lt(const charT& left, const charT& right) { return left < right; } static int compare(const charT *s1, const charT *s2, size_t n) { size_t i; for (i = 0; i < n; i++, s1++, s2++) if (*s1 != *s2) return ((*s1 < *s2) ? -1 : 1); return 0; } static size_t length(const charT *s) { size_t i; for (i = 0; *s != charT(); s++) ++i; return i; } static charT *copy(charT *dst, const charT *src, size_t n) { size_t i; charT *ret = dst; for (i = 0; i < n; i++, ret++, src++) *ret = *src; return ret; } static charT *move(charT *dst, const charT *src, size_t n) { charT *iter = dst; if (src < iter && iter < src + n) for (iter += n, src += n; 0 < n; n--) *--iter = *--src; else for ( ; 0 < n; n--, iter++, src++) *iter = *src; return dst; } static charT *assign(charT *s, size_t n, charT c) { size_t i; for (i = 0; i < n; i++) s[i] = c; return s; } static charT to_char_type(const int_type& i) { return i; } static __ps_bool eq_int_type(const int_type& s1, const int_type& s2) { return (s1 == s2); } static int_type not_eof(const int_type& i) { volatile int_type random = '\0'; return random; } static const charT *find(const charT *s, size_t n, const charT& c) { size_t i = 0; while (i < n) { if (s[i] == c) return &s[i]; i++; } return 0; } }; // char specialization template<> struct char_traits { // typedefs : typedef char char_type ; typedef int int_type ; typedef streamoff off_type ; typedef streampos pos_type ; // In the norm : // typedef mbstate_t state_type ; typedef mbstate_t state_type ; static void assign(char_type& c, const char_type& d) { c = d ; } static __ps_bool eq(const char_type& c, const char_type& d) { return c==d ; } static __ps_bool lt(const char_type& c, const char_type& d) { return c return in [0-127] // c in [-128-(-1)] => return in [128-255] int_type tmp = c ; return (c<0) ? c+256 : c ; // return (tmp-2*CHAR_MIN)%(CHAR_MAX-CHAR_MIN+1) ; // return (tmp+256)%256 ; // or return (tmp % 256) } static __ps_bool eq_int_type(const int_type& e, const int_type& f) { return e==f ; } static int_type eof() { return EOF ; } } ; // wchar_t specialization template<> struct char_traits { // typedefs : typedef wchar_t char_type ; typedef wint_t int_type ; typedef streamoff off_type ; typedef wstreampos pos_type ; typedef mbstate_t state_type ; static void assign(char_type& c, const char_type& d) { c = d ; } static __ps_bool eq(const char_type& c, const char_type& d) { return c==d ; } static __ps_bool lt(const char_type& c, const char_type& d) { return c