00001 //===-- basic/Attributes.cpp ---------------------------------- -*- C++ -*-===// 00002 // 00003 // This file is distributed under the MIT license. See LICENSE.txt for details. 00004 // 00005 // Copyright (C) 2009, Stephen Wilson 00006 // 00007 //===----------------------------------------------------------------------===// 00008 00009 #include "comma/basic/Attributes.h" 00010 #include "comma/basic/IdentifierPool.h" 00011 00012 #include <cstring> 00013 00014 using namespace comma::attrib; 00015 00016 namespace { 00017 00018 static const char *attributeNames[] = { 00019 "First", 00020 "Pos", 00021 "Val", 00022 "Last", 00023 "Range", 00024 }; 00025 00026 } // end anonymous namespace. 00027 00028 const char *comma::attrib::getAttributeString(AttributeID ID) 00029 { 00030 return attributeNames[ID - FIRST_ATTRIB]; 00031 } 00032 00033 void comma::attrib::markAttributeIdentifiers(IdentifierPool &idPool) 00034 { 00035 for (unsigned cursor = FIRST_ATTRIB; cursor <= LAST_ATTRIB; ++cursor) { 00036 AttributeID ID = static_cast<AttributeID>(cursor); 00037 const char *name = getAttributeString(ID); 00038 IdentifierInfo &idInfo = idPool.getIdentifierInfo(name); 00039 idInfo.setAttributeID(ID); 00040 } 00041 } 00042 00043 AttributeID comma::attrib::getAttributeID(const char *start, const char *end) 00044 { 00045 size_t len = end - start; 00046 00047 for (unsigned cursor = FIRST_ATTRIB; cursor <= LAST_ATTRIB; ++cursor) { 00048 AttributeID ID = static_cast<AttributeID>(cursor); 00049 const char *name = getAttributeString(ID); 00050 if (::strlen(name) == len && strncmp(name, start, len) == 0) 00051 return ID; 00052 } 00053 return UNKNOWN_ATTRIBUTE; 00054 }