00001 00002 // 00003 // This file is part of the MADELINE 2 program 00004 // written by Edward H. Trager, Ritu Khanna and Adrian Marrs 00005 // Copyright (c) 2006 by the 00006 // Regents of the University of Michigan. 00007 // All Rights Reserved. 00008 // 00009 // The latest version of this program is available from: 00010 // 00011 // http://eyegene.ophthy.med.umich.edu/madeline/ 00012 // 00013 // Released under the GNU General Public License. 00014 // A copy of the GPL is included in the distribution 00015 // package of this software, or see: 00016 // 00017 // http://www.gnu.org/copyleft/ 00018 // 00019 // ... for licensing details. 00020 // 00022 00023 // 00024 // UniqueList.h 00025 // 00026 #include <map> 00027 #include <vector> 00028 #include <string> 00029 #include "Data.h" 00030 00031 #ifndef UNIQUELIST_INCLUDED 00032 #define UNIQUELIST_INCLUDED 00033 00034 // 00035 // CategoricalInformation 00036 // 00037 // This class is used by UniqueList 00038 // for tracking statistics on each 00039 // level of a variable 00040 // 00041 class CategoricalInformation{ 00042 00043 private: 00044 00045 unsigned int _ordinal; 00046 unsigned int _count; 00047 std::string _label; 00048 00049 public: 00050 00051 // Constructor: 00052 // 00053 CategoricalInformation(){ _ordinal=_count = 0; }; 00054 CategoricalInformation(const std::string &label){ _label=label;}; 00055 CategoricalInformation(const std::string &label,const unsigned ordinal){ _label=label; _ordinal=ordinal;}; 00056 00057 // Convenience increment operator: 00058 void operator++(void){ _count++; }; 00059 00060 void setLabel(const std::string &label){ _label=label; }; 00061 void setOrdinal(const unsigned ordinal){ _ordinal=ordinal;}; 00062 00063 unsigned getCount(void) const { return _count; }; 00064 unsigned getOrdinal(void) const { return _ordinal; }; 00065 std::string getLabel(void) const { return _label; }; 00066 00067 }; 00068 00069 00070 // 00071 // UniqueList 00072 // 00073 class UniqueList{ 00074 00075 private: 00076 00077 std::string _name; // Name of the uniqueListing 00078 unsigned _levels; // Non-missing levels 00079 unsigned _count; // Non-missing summary count 00080 unsigned _countMissing; // Missing count 00081 00082 // 00083 // Comparison Functor: 00084 // 00085 struct _compareData{ 00086 bool operator()( const Data * const d1 , const Data * const d2 ) const{ 00087 00088 return (*d1) < (*d2); 00089 00090 } 00091 }; 00092 00093 typedef std::map<const Data * const,CategoricalInformation,_compareData> UNIQUELIST; 00094 UNIQUELIST _uniqueList; // Map of the levels and counts 00095 00096 public: 00097 00098 // Constructor: 00099 UniqueList(const std::string & name); 00100 // insert: 00101 void insert( const Data *); 00102 00103 unsigned getLevels(void) const { return _levels; } 00104 unsigned getAllLevels(void) const { return _levels+(_countMissing?1:0); } 00105 unsigned getCount(void) const { return _count; } 00106 unsigned getCountMissing(void) const { return _countMissing; } 00107 00108 // Assign ordinals only after having completed 00109 // source list traversal: 00110 void assignOrdinals(void); 00111 00112 // Find the ordinal corresponding to a given key: 00113 unsigned getOrdinalForKey(const Data *dp) const; 00114 // Find the label corresponding to a given key: 00115 void getOrdinalAndLabelForKey(const Data *dp,std::string& label,unsigned& ordinal) const; 00116 std::vector<std::string> getLabels(void) const; 00117 void printResults(void) const; 00118 00119 }; 00120 00121 00122 #endif