44 |
|
|
45 |
#ifdef LIBGIG_HEADER_FILE |
#ifdef LIBGIG_HEADER_FILE |
46 |
# include LIBGIG_HEADER_FILE(gig.h) |
# include LIBGIG_HEADER_FILE(gig.h) |
47 |
|
# include LIBGIG_HEADER_FILE(Serialization.h) |
48 |
#else |
#else |
49 |
# include <gig.h> |
# include <gig.h> |
50 |
|
# include <Serialization.h> |
51 |
#endif |
#endif |
52 |
|
|
53 |
//FIXME: for some reason AC GETTEXT check fails on the Mac cross compiler? |
//FIXME: for some reason AC GETTEXT check fails on the Mac cross compiler? |
116 |
return Glib::convert_with_fallback(utf8_string, GIG_STR_ENCODING, "UTF-8", "?"); |
return Glib::convert_with_fallback(utf8_string, GIG_STR_ENCODING, "UTF-8", "?"); |
117 |
} |
} |
118 |
|
|
119 |
|
inline Glib::ustring ltrim(Glib::ustring s) { |
120 |
|
s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace)))); |
121 |
|
return s; |
122 |
|
} |
123 |
|
|
124 |
|
inline Glib::ustring rtrim(Glib::ustring s) { |
125 |
|
s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end()); |
126 |
|
return s; |
127 |
|
} |
128 |
|
|
129 |
|
inline Glib::ustring trim(Glib::ustring s) { |
130 |
|
return ltrim(rtrim(s)); |
131 |
|
} |
132 |
|
|
133 |
template<class T> inline std::string ToString(T o) { |
template<class T> inline std::string ToString(T o) { |
134 |
std::stringstream ss; |
std::stringstream ss; |
135 |
ss << o; |
ss << o; |
136 |
return ss.str(); |
return ss.str(); |
137 |
} |
} |
138 |
|
|
139 |
|
inline static bool endsWith(const std::string& haystack, const std::string& needle, bool caseSensitive) { |
140 |
|
if (haystack.size() < needle.size()) return false; |
141 |
|
const std::string sub = haystack.substr(haystack.size() - needle.size(), needle.size()); |
142 |
|
return (caseSensitive) ? (sub == needle) : (!strcasecmp(sub.c_str(), needle.c_str())); |
143 |
|
} |
144 |
|
|
145 |
inline int getDimensionIndex(gig::dimension_t type, gig::Region* rgn) { |
inline int getDimensionIndex(gig::dimension_t type, gig::Region* rgn) { |
146 |
for (uint i = 0; i < rgn->Dimensions; ++i) |
for (uint i = 0; i < rgn->Dimensions; ++i) |
147 |
if (rgn->pDimensionDefinitions[i].dimension == type) |
if (rgn->pDimensionDefinitions[i].dimension == type) |
225 |
return dimCase; |
return dimCase; |
226 |
} |
} |
227 |
|
|
228 |
inline std::vector<gig::DimensionRegion*> dimensionRegionsMatching(const DimensionCase& dimCase, gig::Region* rgn) { |
/** |
229 |
|
* Checks whether the passed dimension zones are within the boundaries of the |
230 |
|
* defined dimensions. This is especially relevant if there are dimensions |
231 |
|
* defined with an amount not equal to a power of two, in that case there are |
232 |
|
* unused dimensions regions which should be ignored. |
233 |
|
*/ |
234 |
|
inline bool isUsedCase(const DimensionCase& c, gig::Region* rgn) { |
235 |
|
for (int d = 0; d < rgn->Dimensions; ++d) { |
236 |
|
gig::dimension_t type = rgn->pDimensionDefinitions[d].dimension; |
237 |
|
if (c.find(type) == c.end()) continue; |
238 |
|
int zone = c.find(type)->second; |
239 |
|
if (zone < 0 || zone >= rgn->pDimensionDefinitions[d].zones) |
240 |
|
return false; |
241 |
|
} |
242 |
|
return true; |
243 |
|
} |
244 |
|
|
245 |
|
inline std::vector<gig::DimensionRegion*> dimensionRegionsMatching( |
246 |
|
const DimensionCase& dimCase, gig::Region* rgn, bool skipUnusedZones = false) |
247 |
|
{ |
248 |
std::vector<gig::DimensionRegion*> v; |
std::vector<gig::DimensionRegion*> v; |
249 |
for (int idr = 0; idr < 256; ++idr) { |
for (int idr = 0; idr < 256; ++idr) { |
250 |
if (!rgn->pDimensionRegions[idr]) continue; |
if (!rgn->pDimensionRegions[idr]) continue; |
251 |
DimensionCase c = dimensionCaseOf(rgn->pDimensionRegions[idr]); |
DimensionCase c = dimensionCaseOf(rgn->pDimensionRegions[idr]); |
252 |
if (!dimCase.isViolating(c)) v.push_back(rgn->pDimensionRegions[idr]); |
if (dimCase.isViolating(c)) continue; |
253 |
|
if (skipUnusedZones && !isUsedCase(c, rgn)) continue; |
254 |
|
v.push_back(rgn->pDimensionRegions[idr]); |
255 |
} |
} |
256 |
return v; |
return v; |
257 |
} |
} |
265 |
return NULL; |
return NULL; |
266 |
} |
} |
267 |
|
|
268 |
|
template<typename T_Message> |
269 |
|
class SignalGuard { |
270 |
|
public: |
271 |
|
SignalGuard(sigc::signal<void, T_Message>& start, sigc::signal<void, T_Message>& end, T_Message message) |
272 |
|
: m_end(end), m_message(message) |
273 |
|
{ |
274 |
|
if (message) start.emit(message); |
275 |
|
} |
276 |
|
|
277 |
|
virtual ~SignalGuard() { |
278 |
|
if (m_message) m_end.emit(m_message); |
279 |
|
} |
280 |
|
protected: |
281 |
|
sigc::signal<void, T_Message>& m_end; |
282 |
|
T_Message m_message; |
283 |
|
}; |
284 |
|
|
285 |
#endif // GIGEDIT_GLOBAL_H |
#endif // GIGEDIT_GLOBAL_H |