"Fossies" - the Fresh Open Source Software Archive

Member "OpenSP-1.5.2/include/XcharMap.h" (21 Jul 2005, 1617 Bytes) of package /linux/misc/old/OpenSP-1.5.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "XcharMap.h" see the Fossies "Dox" file reference documentation.

    1 // Copyright (c) 1994 James Clark, 2000 Matthias Clasen
    2 // See the file COPYING for copying permission.
    3 
    4 #ifndef XcharMap_INCLUDED
    5 #define XcharMap_INCLUDED 1
    6 
    7 #include "types.h"
    8 #include "Resource.h"
    9 #include "Ptr.h"
   10 #include "constant.h"
   11 #include "CharMap.h"
   12 
   13 #ifdef SP_NAMESPACE
   14 namespace SP_NAMESPACE {
   15 #endif
   16 
   17 template<class T>
   18 class SharedXcharMap : public Resource {
   19 public:
   20   SharedXcharMap();
   21   SharedXcharMap(T defaultValue);
   22   T *ptr() { return v + 1; }
   23 private:
   24 #ifdef SP_MULTI_BYTE
   25   T v[2 + 0xffff];
   26 #else
   27   T v[2 + 0xff];
   28 #endif
   29 };
   30 
   31 template<class T>
   32 class XcharMap {
   33 public:
   34   XcharMap();
   35   XcharMap(T defaultValue);
   36   T operator[](Xchar c) const;
   37   void setRange(Char min, Char max, T val);
   38   void setChar(Char c, T val);
   39   void setEe(T val);
   40   void clear();
   41 private:
   42   T *ptr_;
   43   Ptr<SharedXcharMap<T> > sharedMap_;
   44 #ifdef SP_MULTI_BYTE
   45   Ptr<CharMapResource<T> > hiMap_;
   46 #endif
   47 };
   48 
   49 
   50 template<class T>
   51 inline  
   52 T XcharMap<T>::operator[](Xchar c) const 
   53 { 
   54 #ifdef SP_MULTI_BYTE
   55   if (c > 0xffff) 
   56     return hiMap_->operator[]((Char)c);
   57 #endif
   58   return ptr_[c]; 
   59 }
   60 
   61 template<class T>
   62 inline 
   63 void XcharMap<T>::setChar(Char c, T val) 
   64 { 
   65 #ifdef SP_MULTI_BYTE
   66   if (c > 0xffff) {
   67     hiMap_->setChar(c, val);
   68     return;
   69   }
   70 #endif
   71   ptr_[c] = val;  
   72 }
   73 
   74 template<class T>
   75 inline 
   76 void XcharMap<T>::setEe(T val)
   77 { 
   78   ptr_[-1] = val; 
   79 }
   80 
   81 template<class T>
   82 inline 
   83 void XcharMap<T>::clear() 
   84 { 
   85   ptr_ = 0; 
   86   sharedMap_.clear(); 
   87 #ifdef SP_MULTI_BYTE
   88   hiMap_.clear(); 
   89 #endif
   90 }
   91 
   92 #ifdef SP_NAMESPACE
   93 }
   94 #endif
   95 
   96 #endif /* not XcharMap_INCLUDED */
   97 
   98 #ifdef SP_DEFINE_TEMPLATES
   99 #include "XcharMap.cxx"
  100 #endif