Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:49:55

0001 #pragma once
0002 /**
0003 suniquename.h
0004 ==============
0005 
0006 This allows storing large numbers of repetitive names 
0007 without repeating them, by storing integer indices 
0008 into the names vector instead of storing all the repeated 
0009 names.  
0010 
0011 **/
0012 
0013 #include <string>
0014 #include <vector>
0015 #include <sstream>
0016 #include <iomanip>
0017 
0018 struct suniquename
0019 {
0020     static int Add(const char* name, std::vector<std::string>& names ) ;    
0021     static std::string Desc( const std::vector<std::string>& names ) ; 
0022 }; 
0023 
0024 /**
0025 suniquename::Add
0026 ------------------
0027 
0028 Returns the index of the name in the vector, after first 
0029 adding the name to the vector if not already present. 
0030 A positive integer value is always returned. 
0031 
0032 **/
0033 
0034 inline int suniquename::Add( const char* name, std::vector<std::string>& names ) // static
0035 {
0036     size_t size = names.size() ; 
0037     size_t idx = std::distance( names.begin(), std::find( names.begin(), names.end(), name ) ); 
0038     if(idx == size) names.push_back(name) ; 
0039     return idx  ; 
0040 }
0041 
0042 inline std::string suniquename::Desc( const std::vector<std::string>& names )
0043 {
0044     std::stringstream ss ; 
0045     for(size_t i=0 ; i < names.size() ; i++ ) ss << std::setw(7) << i << " : " << names[i] << std::endl ; 
0046     std::string str = ss.str(); 
0047     return str ; 
0048 }
0049