Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /*
0002  * Copyright (c) 2019 Opticks Team. All Rights Reserved.
0003  *
0004  * This file is part of Opticks
0005  * (see https://bitbucket.org/simoncblyth/opticks).
0006  *
0007  * Licensed under the Apache License, Version 2.0 (the "License"); 
0008  * you may not use this file except in compliance with the License.  
0009  * You may obtain a copy of the License at
0010  *
0011  *   http://www.apache.org/licenses/LICENSE-2.0
0012  *
0013  * Unless required by applicable law or agreed to in writing, software 
0014  * distributed under the License is distributed on an "AS IS" BASIS, 
0015  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
0016  * See the License for the specific language governing permissions and 
0017  * limitations under the License.
0018  */
0019 
0020 #pragma once
0021 
0022 /**
0023 SSortKV
0024 ==========
0025 
0026 Utility struct for reordering a vector of string float pairs.
0027 
0028 **/
0029 
0030 
0031 #include <map>
0032 #include <string>
0033 #include <vector>
0034 #include <algorithm>
0035 #include "SYSRAP_API_EXPORT.hh"
0036  
0037 struct SYSRAP_API SSortKV 
0038 {
0039     typedef std::pair<std::string, float> KV ; 
0040     typedef std::vector<KV> VKV ;
0041 
0042     SSortKV(bool descending_) : descending(descending_) {} 
0043 
0044     void add(const char* k, float v)
0045     {    
0046         vkv.push_back(KV(k, v));
0047     }    
0048     void sort()
0049     {    
0050         std::sort(vkv.begin(), vkv.end(), *this );
0051     }    
0052     void dump(const char* msg="SSortKV::dump") const ;
0053 
0054     bool operator()( const KV& a, const KV& b) const 
0055     {    
0056         return descending ? a.second > b.second : a.second < b.second ; 
0057     }    
0058     unsigned getNum() const  
0059     {
0060         return vkv.size();
0061     }
0062     const std::string& getKey(unsigned i) const 
0063     {    
0064         return vkv[i].first ; 
0065     }    
0066     float getVal(unsigned i) const 
0067     {    
0068         return vkv[i].second ; 
0069     }    
0070 
0071     VKV   vkv ; 
0072     bool  descending ;  
0073 
0074 };
0075