Coconut XML Framework  beta
CNXMLDecodeError.h
Go to the documentation of this file.
00001 
00008 #ifndef CNXMLDECODEERROR_H
00009 #define CNXMLDECODEERROR_H
00010 
00011 #include <Coconut/Coconut.h>
00012 #include <libxml/tree.h>
00013 
00015 typedef enum {
00017         CNXMLNoDecodeError                                              = 0,
00019         CNXMLIsNotElementNodeError,
00021         CNXMLChildIsNotFoundError,
00023         CNXMLInvalidElementNameError,
00025         CNXMLNoAttributeNameError,
00027         CNXMLInvalidAttributeValueError,
00029         CNXMLInvalidContextError
00030 } CNXMLDecodeErrorType ;
00031 
00035 struct CNXMLDecodeError
00036 {
00038         CNXMLDecodeErrorType                    errorType ;
00040         xmlNodePtr                                              errorNode ;
00042         union {
00044                 struct {
00046                         const xmlChar *         requiredElementName ;
00047                 } invalidElementName ;
00049                 struct {
00051                         const xmlChar *         requiredElementName ;
00052                 } childIsNotFound ;
00054                 struct {
00056                         const xmlChar *         requiredAttributeName ;
00057                 } noAttributeName ;
00059                 struct {
00061                         const xmlChar *         attributeName ;
00063                         const xmlChar *         invalidValue ;
00064                 } invalidAttributeValue ;
00065         } context ;
00066 } ;
00067 
00073 static inline CNXMLDecodeErrorType
00074 CNXMLTypeOfDecodeError(const struct CNXMLDecodeError * src)
00075 {
00076         return src->errorType ;
00077 }
00078 
00083 static inline void
00084 CNXMLSetNoDecodeError(struct CNXMLDecodeError * dst)
00085 {
00086         dst->errorType = CNXMLNoDecodeError ;
00087         dst->errorNode = NULL ;
00088 }
00089 
00095 static inline void
00096 CNXMLSetIsNotElementNodeError(struct CNXMLDecodeError * dst, xmlNodePtr node)
00097 {
00098         dst->errorType = CNXMLIsNotElementNodeError ;
00099         dst->errorNode = node ; 
00100 }
00101 
00108 static inline void
00109 CNXMLSetChildIsNotFoundError(struct CNXMLDecodeError * dst, xmlNodePtr node, const xmlChar * reqname)
00110 {
00111         dst->errorType = CNXMLChildIsNotFoundError ;
00112         dst->errorNode = node ;
00113         (dst->context).childIsNotFound.requiredElementName = reqname ;
00114 }
00115 
00122 static inline void
00123 CNXMLSetInvalidElementNameError(struct CNXMLDecodeError * dst, xmlNodePtr node, const xmlChar * reqname)
00124 {
00125         dst->errorType = CNXMLInvalidElementNameError ;
00126         dst->errorNode = node ;
00127         (dst->context).invalidElementName.requiredElementName = reqname ;
00128 }
00129 
00136 static inline void
00137 CNXMLSetNoAttributeNameError(struct CNXMLDecodeError * dst, xmlNodePtr node, const xmlChar * reqname)
00138 {
00139         dst->errorType = CNXMLNoAttributeNameError ;
00140         dst->errorNode = node ;
00141         (dst->context).noAttributeName.requiredAttributeName = reqname ;
00142 }
00143 
00151 static inline void
00152 CNXMLSetInvalidAttributeValueError(struct CNXMLDecodeError * dst, xmlNodePtr node, const xmlChar * attrname, const xmlChar * invval)
00153 {
00154         dst->errorType = CNXMLInvalidAttributeValueError ;
00155         dst->errorNode = node ;
00156         (dst->context).invalidAttributeValue.attributeName = attrname ;
00157         (dst->context).invalidAttributeValue.invalidValue = invval ;
00158 }
00159 
00165 static inline void
00166 CNXMLSetInvalidContextError(struct CNXMLDecodeError * dst, xmlNodePtr node)
00167 {
00168         dst->errorType = CNXMLInvalidContextError ;
00169         dst->errorNode = node ;
00170 }
00171 
00178 struct CNString *
00179 CNXMLDecodeErrorToString(const struct CNXMLDecodeError * src, struct CNResource * resource) ;
00180 
00181 #endif  /* CNXMLDECODEERROR_H */
00182