1 #ifndef MOBI_MTLD_COMMON 2 #define MOBI_MTLD_COMMON 11 #include <sys/types.h> 14 #include <mtld/util.h> 15 #include <mtld/exception.h> 18 #if defined(WIN32) || defined(WIN64) 19 #define strcasecmp _stricmp 20 #define strncasecmp _strnicmp 21 #define strtok_r strtok_s 22 #define strtoll _strtoi64 23 #define strtoull _strtoui64 24 #define snprintf _snprintf 31 namespace Mobi {
namespace Mtld {
namespace Da {
41 struct attrvec :
public std::map<size_t, const Value *> {
42 attrvec() : std::map<size_t, const Value *>() {}
62 NoSuchProperty(std::string name) { *
this <<
"no such property \"" << name <<
"\""; }
63 NoSuchProperty(
int idx) { *
this <<
"no property at index " << idx; }
103 *
this <<
": " << typec;
125 enum PropertyType { Integer, String, Bool, Float, Set };
135 typedef std::vector<Value *> valueset;
138 operator<<(ostream &,
const valueset &);
155 const char *strval()
const {
160 float floatval()
const {
165 const valueset setval()
const {
170 long longval()
const {
175 operator bool()
const;
176 operator std::string()
const;
177 operator long()
const;
178 operator float()
const;
179 int compare(
const Value &)
const;
181 std::string toString()
const {
return std::string(*
this); }
198 template<
typename signedT>
199 static signedT atoi(
const char *);
200 template<
typename unsignedT>
201 static unsignedT atou(
const char *);
202 template<
typename realT>
203 static realT atof(
const char *);
207 bool operator()(
const std::string & a,
const std::string & b)
const {
208 return strncasecmp(a.c_str(), b.c_str(), b.size()) < 0;
212 typedef std::map<std::string, std::string, CaseInsensitiveLess> HeaderMap;
221 DA_EXPORT
extern const char **defaultHeaderPriorities[];
239 typedef std::vector<const Property *> propvec;
253 class constcharless {
255 bool operator()(
const char *l,
const char *r)
const {
256 return strcmp(l, r) < 0;
262 typedef std::map<const char *, const Property *, constcharless> propByNameMap;
263 propByNameMap propertiesByName;
267 propvec &getProperties() {
return properties; }
268 const propvec &getProperties()
const {
return properties; }
271 const Property &addProperty(
const char *name, PropertyType type);
272 const Property *findPropertyDescr(
const char *p)
const;
274 const Property &getPropertyDescr(
const char *p)
const;
275 const Property &getPropertyDescr(
size_t off)
const;
277 size_t getPropertyCount()
const {
return getProperties().size(); }
285 char *strdup(
const char *);
286 char *strdup(
const char *,
size_t);
289 virtual ~CommonDeviceAtlas() {}
290 virtual int getDataRevision()
const = 0;
291 virtual time_t getDataGeneration()
const = 0;
306 const Value **globalAttrs;
312 char *strdup(
const char *from,
size_t len = -1);
314 virtual size_t size()
const = 0;
315 virtual bool empty() = 0;
323 void getProperty(
const Property &prop,
int &value);
324 void getProperty(
const Property &prop,
const char *&value);
325 void getProperty(
const Property &prop,
bool &value);
327 virtual const Value *findProperty(
const Property &p)
const = 0;
328 virtual const Value *findProperty(
size_t)
const = 0;
329 virtual void setProperty(
const Property &,
const Value *) = 0;
330 virtual void setProperty(
size_t,
const Value *) = 0;
331 virtual const Property &getPropertyDescr(
const char *, PropertyType *) = 0;
332 virtual const Property &getPropertyDescr(
size_t idx)
const = 0;
337 void getProperty(
const char *prop,
const Value *&value)
338 { getProperty(getPropertyDescr(prop, 0), value); }
339 void getProperty(
const char *prop,
int &value)
340 { getProperty(getPropertyDescr(prop, 0), value); }
341 void getProperty(
const char *prop,
const char *&value)
342 { getProperty(getPropertyDescr(prop, 0), value); }
343 void getProperty(
const char *prop,
bool &value)
344 { getProperty(getPropertyDescr(prop, 0), value); }
346 bool hasProperty(
const Property &prop) {
return findProperty(prop.index) != 0; }
354 template <
typename T>
355 bool contains(
const char *propname, T tocheck);
359 virtual const Value *operator[](
const char *propname)
const = 0;
361 DA_EXPORT std::ostream &operator<<(std::ostream &,
const PropertyType &);
362 DA_EXPORT std::ostream &operator<<(std::ostream &,
const Property &);
363 static inline std::ostream &operator << (std::ostream &os,
const Value &v)
364 {
return os << std::string(v); }
366 inline bool CommonDeliveryContext::contains<const char *>(
const char *,
const char *);
368 #include <mtld/common.tpp>
Definition: exception.h:16
Definition: common_priv.h:36
const propvec & getPropertyNames() const
Returns the Json's properties list.
Definition: common.h:282