/[svn]/gigedit/trunk/src/gigedit/global.h
ViewVC logotype

Diff of /gigedit/trunk/src/gigedit/global.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3157 by schoenebeck, Mon May 8 17:30:10 2017 UTC revision 3341 by schoenebeck, Mon Jul 31 11:26:56 2017 UTC
# Line 25  Line 25 
25  #endif  #endif
26    
27  #include <cstring>  #include <cstring>
28    #include <algorithm>
29    
30  #include <glibmmconfig.h>  #include <glibmmconfig.h>
31  // threads.h must be included first to be able to build with  // threads.h must be included first to be able to build with
# Line 116  gig::String gig_from_utf8(const Glib::us Line 117  gig::String gig_from_utf8(const Glib::us
117      return Glib::convert_with_fallback(utf8_string, GIG_STR_ENCODING, "UTF-8", "?");      return Glib::convert_with_fallback(utf8_string, GIG_STR_ENCODING, "UTF-8", "?");
118  }  }
119    
120    inline Glib::ustring ltrim(Glib::ustring s) {
121        s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
122        return s;
123    }
124    
125    inline Glib::ustring rtrim(Glib::ustring s) {
126        s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
127        return s;
128    }
129    
130    inline Glib::ustring trim(Glib::ustring s) {
131        return ltrim(rtrim(s));
132    }
133    
134  template<class T> inline std::string ToString(T o) {  template<class T> inline std::string ToString(T o) {
135      std::stringstream ss;      std::stringstream ss;
136      ss << o;      ss << o;
137      return ss.str();      return ss.str();
138  }  }
139    
140    inline static bool endsWith(const std::string& haystack, const std::string& needle, bool caseSensitive) {
141        if (haystack.size() < needle.size()) return false;
142        const std::string sub = haystack.substr(haystack.size() - needle.size(), needle.size());
143        return (caseSensitive) ? (sub == needle) : (!strcasecmp(sub.c_str(), needle.c_str()));
144    }
145    
146  inline int getDimensionIndex(gig::dimension_t type, gig::Region* rgn) {  inline int getDimensionIndex(gig::dimension_t type, gig::Region* rgn) {
147      for (uint i = 0; i < rgn->Dimensions; ++i)      for (uint i = 0; i < rgn->Dimensions; ++i)
148          if (rgn->pDimensionDefinitions[i].dimension == type)          if (rgn->pDimensionDefinitions[i].dimension == type)
# Line 205  inline DimensionCase dimensionCaseOf(gig Line 226  inline DimensionCase dimensionCaseOf(gig
226      return dimCase;      return dimCase;
227  }  }
228    
229  inline std::vector<gig::DimensionRegion*> dimensionRegionsMatching(const DimensionCase& dimCase, gig::Region* rgn) {  /**
230     * Checks whether the passed dimension zones are within the boundaries of the
231     * defined dimensions. This is especially relevant if there are dimensions
232     * defined with an amount not equal to a power of two, in that case there are
233     * unused dimensions regions which should be ignored.
234     */
235    inline bool isUsedCase(const DimensionCase& c, gig::Region* rgn) {
236        for (int d = 0; d < rgn->Dimensions; ++d) {
237            gig::dimension_t type = rgn->pDimensionDefinitions[d].dimension;
238            if (c.find(type) == c.end()) continue;
239            int zone = c.find(type)->second;
240            if (zone < 0 || zone >= rgn->pDimensionDefinitions[d].zones)
241                return false;
242        }
243        return true;
244    }
245    
246    inline std::vector<gig::DimensionRegion*> dimensionRegionsMatching(
247        const DimensionCase& dimCase, gig::Region* rgn, bool skipUnusedZones = false)
248    {
249      std::vector<gig::DimensionRegion*> v;      std::vector<gig::DimensionRegion*> v;
250      for (int idr = 0; idr < 256; ++idr) {      for (int idr = 0; idr < 256; ++idr) {
251          if (!rgn->pDimensionRegions[idr]) continue;          if (!rgn->pDimensionRegions[idr]) continue;
252          DimensionCase c = dimensionCaseOf(rgn->pDimensionRegions[idr]);          DimensionCase c = dimensionCaseOf(rgn->pDimensionRegions[idr]);
253          if (!dimCase.isViolating(c)) v.push_back(rgn->pDimensionRegions[idr]);          if (dimCase.isViolating(c)) continue;
254            if (skipUnusedZones && !isUsedCase(c, rgn)) continue;
255            v.push_back(rgn->pDimensionRegions[idr]);
256      }      }
257      return v;      return v;
258  }  }
# Line 224  inline gig::DimensionRegion* dimensionRe Line 266  inline gig::DimensionRegion* dimensionRe
266      return NULL;      return NULL;
267  }  }
268    
269    template<typename T_Message>
270    class SignalGuard {
271    public:
272        SignalGuard(sigc::signal<void, T_Message>& start, sigc::signal<void, T_Message>& end, T_Message message)
273            : m_end(end), m_message(message)
274        {
275            if (message) start.emit(message);
276        }
277    
278        virtual ~SignalGuard() {
279            if (m_message) m_end.emit(m_message);
280        }
281    protected:
282        sigc::signal<void, T_Message>& m_end;
283        T_Message m_message;
284    };
285    
286  #endif // GIGEDIT_GLOBAL_H  #endif // GIGEDIT_GLOBAL_H

Legend:
Removed from v.3157  
changed lines
  Added in v.3341

  ViewVC Help
Powered by ViewVC