Path: blob/master/thirdparty/graphite/src/inc/FeatureMap.h
9906 views
// SPDX-License-Identifier: MIT OR MPL-2.0 OR LGPL-2.1-or-later OR GPL-2.0-or-later1// Copyright 2010, SIL International, All rights reserved.23#pragma once4#include "inc/Main.h"5#include "inc/FeatureVal.h"67namespace graphite2 {89// Forward declarations for implmentation types10class FeatureMap;11class Face;121314class FeatureSetting15{16public:17FeatureSetting(int16 theValue, uint16 labelId) : m_label(labelId), m_value(theValue) {};18uint16 label() const { return m_label; }19int16 value() const { return m_value; }2021CLASS_NEW_DELETE;22private:23FeatureSetting(const FeatureSetting & fs) : m_label(fs.m_label), m_value(fs.m_value) {};2425uint16 m_label;26int16 m_value;27};2829class FeatureRef30{31typedef uint32 chunk_t;32static const uint8 SIZEOF_CHUNK = sizeof(chunk_t)*8;3334public:35enum flags_t : uint16 {36HIDDEN = 0x080037};38FeatureRef() throw();39FeatureRef(const Face & face, unsigned short & bits_offset, uint32 max_val,40uint32 name, uint16 uiName, flags_t flags,41FeatureSetting *settings, uint16 num_set) throw();42~FeatureRef() throw();4344bool applyValToFeature(uint32 val, Features& pDest) const; //defined in GrFaceImp.h45void maskFeature(Features & pDest) const {46if (m_index < pDest.size()) //defensive47pDest[m_index] |= m_mask;48}4950uint32 getFeatureVal(const Features& feats) const; //defined in GrFaceImp.h5152uint32 getId() const { return m_id; }53uint16 getNameId() const { return m_nameid; }54uint16 getNumSettings() const { return m_numSet; }55uint16 getSettingName(uint16 index) const { return m_nameValues[index].label(); }56int16 getSettingValue(uint16 index) const { return m_nameValues[index].value(); }57flags_t getFlags() const { return m_flags; }58uint32 maxVal() const { return m_max; }59const Face & getFace() const { assert(m_face); return *m_face;}60const FeatureMap* getFeatureMap() const;// { return m_pFace;}6162CLASS_NEW_DELETE;63private:64FeatureRef(const FeatureRef & rhs);6566const Face * m_face;67FeatureSetting * m_nameValues; // array of name table ids for feature values68chunk_t m_mask, // bit mask to get the value from the vector69m_max; // max value the value can take70uint32 m_id; // feature identifier/name71uint16 m_nameid, // Name table id for feature name72m_numSet; // number of values (number of entries in m_nameValues)73flags_t m_flags; // feature flags see FeatureRef::flags_t.74byte m_bits, // how many bits to shift the value into place75m_index; // index into the array to find the ulong to mask7677private: //unimplemented78FeatureRef& operator=(const FeatureRef&);79};8081inline82FeatureRef::FeatureRef() throw()83: m_face(0),84m_nameValues(0),85m_mask(0), m_max(0),86m_id(0), m_nameid(0), m_numSet(0),87m_flags(flags_t(0)),88m_bits(0), m_index(0)89{90}919293class NameAndFeatureRef94{95public:96NameAndFeatureRef(uint32 name = 0) : m_name(name) , m_pFRef(NULL){}97NameAndFeatureRef(FeatureRef const & p) : m_name(p.getId()), m_pFRef(&p) {}9899bool operator<(const NameAndFeatureRef& rhs) const //orders by m_name100{ return m_name<rhs.m_name; }101102CLASS_NEW_DELETE103104uint32 m_name;105const FeatureRef* m_pFRef;106};107108class FeatureMap109{110public:111FeatureMap() : m_numFeats(0), m_feats(NULL), m_pNamedFeats(NULL) {}112~FeatureMap() { delete[] m_feats; delete[] m_pNamedFeats; }113114bool readFeats(const Face & face);115const FeatureRef *findFeatureRef(uint32 name) const;116FeatureRef *feature(uint16 index) const { return m_feats + index; }117//GrFeatureRef *featureRef(byte index) { return index < m_numFeats ? m_feats + index : NULL; }118const FeatureRef *featureRef(byte index) const { return index < m_numFeats ? m_feats + index : NULL; }119FeatureVal* cloneFeatures(uint32 langname/*0 means default*/) const; //call destroy_Features when done.120uint16 numFeats() const { return m_numFeats; };121CLASS_NEW_DELETE122private:123friend class SillMap;124uint16 m_numFeats;125126FeatureRef *m_feats;127NameAndFeatureRef* m_pNamedFeats; //owned128FeatureVal m_defaultFeatures; //owned129130private: //defensive on m_feats, m_pNamedFeats, and m_defaultFeatures131FeatureMap(const FeatureMap&);132FeatureMap& operator=(const FeatureMap&);133};134135136class SillMap137{138private:139class LangFeaturePair140{141LangFeaturePair(const LangFeaturePair &);142LangFeaturePair & operator = (const LangFeaturePair &);143144public:145LangFeaturePair() : m_lang(0), m_pFeatures(0) {}146~LangFeaturePair() { delete m_pFeatures; }147148uint32 m_lang;149Features* m_pFeatures; //owns150CLASS_NEW_DELETE151};152public:153SillMap() : m_langFeats(NULL), m_numLanguages(0) {}154~SillMap() { delete[] m_langFeats; }155bool readFace(const Face & face);156bool readSill(const Face & face);157FeatureVal* cloneFeatures(uint32 langname/*0 means default*/) const; //call destroy_Features when done.158uint16 numLanguages() const { return m_numLanguages; };159uint32 getLangName(uint16 index) const { return (index < m_numLanguages)? m_langFeats[index].m_lang : 0; };160161const FeatureMap & theFeatureMap() const { return m_FeatureMap; };162private:163FeatureMap m_FeatureMap; //of face164LangFeaturePair * m_langFeats;165uint16 m_numLanguages;166167private: //defensive on m_langFeats168SillMap(const SillMap&);169SillMap& operator=(const SillMap&);170};171172} // namespace graphite2173174struct gr_feature_ref : public graphite2::FeatureRef {};175176177