Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

IdentifierUtil.h

Go to the documentation of this file.
00001 //                            Package   : omniIFR
00002 //  IdentifierUtil.h          Created   : 2004/03/19
00003 //                            Author    : Alex Tingle
00004 //
00005 //    Copyright (C) 2004 Alex Tingle.
00006 //
00007 //    This file is part of the omniIFR application.
00008 //
00009 //    omniIFR is free software; you can redistribute it and/or
00010 //    modify it under the terms of the GNU Lesser General Public
00011 //    License as published by the Free Software Foundation; either
00012 //    version 2.1 of the License, or (at your option) any later version.
00013 //
00014 //    omniIFR is distributed in the hope that it will be useful,
00015 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 //    Lesser General Public License for more details.
00018 //
00019 //    You should have received a copy of the GNU Lesser General Public
00020 //    License along with this library; if not, write to the Free Software
00021 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 //
00023 #ifndef OMNIIFR__IDENTIFIERUTIL_H
00024 #define OMNIIFR__IDENTIFIERUTIL_H
00025 
00026 #ifdef HAVE_CONFIG_H
00027 #  include "config.h"
00028 #endif
00029 
00030 #ifdef HAVE_OMNIORB3
00031 #  include <omniORB3/CORBA.h>
00032 #endif
00033 
00034 #ifdef HAVE_OMNIORB4
00035 #  include <omniORB4/CORBA.h>
00036 #endif
00037 
00038 #include <ctype.h> // tolower
00039 #include <string.h> // strcmp, strcasecmp
00040 
00041 namespace Omniifr {
00042 
00045 class IdentifierUtil
00046 {
00047 public:
00048 
00049   enum Match{
00050     equalMatch,      
00051     equivalentMatch, 
00052     noMatch          
00053   };
00054   
00055   inline static Match compare(const char* n1, const char* n2)
00056   {
00057     if(!n1 || !n2)
00058         return noMatch;
00059     else if(0==strcmp(n1,n2))
00060         return equalMatch;
00061     else if(0==strcasecmp(n1,n2))
00062         return equivalentMatch;
00063     else
00064         return noMatch;
00065   }
00066 
00070   inline static void checkInvalid(const char* name)
00071   {
00072     // Should not be testing NULL pointers.
00073     assert(name);
00074 
00075     bool valid =bool( name[0] ); // string not empty
00076 
00077     if(valid)
00078     {
00079       for(int i=0; name[i]; ++i)
00080       {
00081         char c =tolower(name[i]);
00082         if( ('a'<=c && c<='z') ||
00083             (i>0 &&
00084               ( ('0'<=c && c<='9') ||
00085                 c=='_'
00086           ) ) )
00087         {
00088           continue; // still valid
00089         }
00090         valid=false;
00091         break;
00092       }
00093     }
00094 
00095     if(!valid)
00096     {
00097       throw CORBA::BAD_PARAM(
00098         IFELSE_OMNIORB4(omni::BAD_PARAM_InvalidName,15),
00099         CORBA::COMPLETED_NO
00100       );
00101     }
00102   }
00103 };
00104 
00105 } // end namespace Omniifr
00106 
00107 #endif // OMNIIFR__IDENTIFIERUTIL_H

Generated on Fri Mar 4 13:03:23 2005 for OmniIFR by  doxygen 1.4.1