Home | History | Annotate | Download | only in src
      1 /* ------------------------------------------------------------------
      2  * Copyright (C) 1998-2009 PacketVideo
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
     13  * express or implied.
     14  * See the License for the specific language governing permissions
     15  * and limitations under the License.
     16  * -------------------------------------------------------------------
     17  */
     18 // -*- c++ -*-
     19 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
     20 
     21 //                     O S C L _ N A M E S T R I N G
     22 
     23 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
     24 
     25 /*! \addtogroup osclerror OSCL Error
     26  *
     27  * @{
     28  */
     29 
     30 
     31 /** \file oscl_namestring.h
     32     \brief Name string class include file.
     33 */
     34 
     35 #ifndef OSCL_NAMESTRING_H_INCLUDED
     36 #define OSCL_NAMESTRING_H_INCLUDED
     37 
     38 #ifndef OSCL_BASE_H_INCLUDED
     39 #include "oscl_base.h"
     40 #endif
     41 
     42 /**
     43 // Name string class appropriate for passing
     44 // short constant ASCII strings around.
     45 // All strings are automatically truncated
     46 // and null-terminated.
     47 */
     48 template<int __len>
     49 class OsclNameString
     50 {
     51     public:
     52         OsclNameString()
     53         {
     54             Set("");
     55         }
     56 
     57         OsclNameString(const char a[])
     58         {
     59             Set((uint8*)a);
     60         }
     61 
     62         OsclNameString(uint8* a)
     63         {
     64             Set(a);
     65         }
     66 
     67         /**
     68         * Set the string to the input value.  The string
     69         * will be truncated to fit the storage class and
     70         * automatically null-terminated.
     71         *
     72         * @param a (input param): null-terminated character
     73         *    string.
     74         */
     75         void Set(uint8* a)
     76         {
     77             for (int i = 0; i < __len; i++)
     78                 iStr[i] = '\0';
     79             if (a)
     80             {
     81                 for (int i = 0; i < __len - 1; i++)
     82                 {
     83                     iStr[i] = a[i];
     84                     if (a[i] == '\0')
     85                         return;
     86                 }
     87             }
     88         }
     89 
     90         void Set(const char a[])
     91         {
     92             Set((uint8*)a);
     93         }
     94 
     95         uint8* Str()const
     96         {
     97             return (uint8*)&iStr[0];
     98         }
     99 
    100         int32 MaxLen()const
    101         {
    102             return __len;
    103         }
    104 
    105     private:
    106         uint8 iStr[__len];
    107 };
    108 #endif
    109 
    110 /*! @} */
    111