Hoyt's FORK of DemoIccMAX 2.1.17.hoyt
Documentation for Hoyt's FORK of DemoIccMAX
Loading...
Searching...
No Matches
CIccXmlArrayType< T, Tsig > Class Template Reference

#include <IccUtilXml.h>

+ Collaboration diagram for CIccXmlArrayType< T, Tsig >:

Public Member Functions

 CIccXmlArrayType ()
 
 CIccXmlArrayType ()
 
T * GetBuf ()
 
icUInt32Number GetSize ()
 
bool ParseArray (xmlNode *pNode)
 
icUInt32Number ParseText (T *pBuf, icUInt32Number nSize, const char *szText)
 
bool ParseTextArray (const char *szText)
 
bool ParseTextArray (xmlNode *pNode)
 
bool ParseTextArrayNum (const char *szText, icUInt32Number num, std::string &parseStr)
 
bool SetSize (icUInt32Number nSize)
 
 ~CIccXmlArrayType ()
 
 ~CIccXmlArrayType ()
 

Static Public Member Functions

static bool DumpArray (std::string &xml, std::string blanks, T *buf, icUInt32Number nBufSize, icConvertType nType, icUInt8Number nColumns)
 
static bool ParseArray (T *buf, icUInt32Number nBufSize, xmlNode *pNode)
 
static icUInt32Number ParseText (T *buf, icUInt32Number nBufSize, const char *szText)
 
static icUInt32Number ParseTextCount (const char *szText)
 
static icUInt32Number ParseTextCountNum (const char *szText, icUInt32Number num, std::string &parseStr)
 

Public Attributes

icUInt32Number m_nSize
 
T * m_pBuf
 

Detailed Description

template<class T, icTagTypeSignature Tsig>
class CIccXmlArrayType< T, Tsig >

Definition at line 44 of file TestParseText.cpp.

Constructor & Destructor Documentation

◆ CIccXmlArrayType() [1/2]

template<class T , icTagTypeSignature Tsig>
CIccXmlArrayType< T, Tsig >::CIccXmlArrayType ( )
inline

Definition at line 49 of file TestParseText.cpp.

49: m_pBuf(nullptr), m_nSize(0) {}
icUInt32Number m_nSize

◆ ~CIccXmlArrayType() [1/2]

template<class T , icTagTypeSignature Tsig>
CIccXmlArrayType< T, Tsig >::~CIccXmlArrayType ( )
inline

Definition at line 50 of file TestParseText.cpp.

50{ delete[] m_pBuf; }

References CIccXmlArrayType< T, Tsig >::m_pBuf.

◆ CIccXmlArrayType() [2/2]

template<class T , icTagTypeSignature Tsig>
CIccXmlArrayType< T, Tsig >::CIccXmlArrayType ( )

◆ ~CIccXmlArrayType() [2/2]

template<class T , icTagTypeSignature Tsig>
CIccXmlArrayType< T, Tsig >::~CIccXmlArrayType ( )

Member Function Documentation

◆ DumpArray()

template<class T , icTagTypeSignature Tsig>
bool CIccXmlArrayType< T, Tsig >::DumpArray ( std::string & xml,
std::string blanks,
T * buf,
icUInt32Number nBufSize,
icConvertType nType,
icUInt8Number nColumns )
static

Definition at line 820 of file IccUtilXml.cpp.

822{
823 char str[200];
824
825 if (!nColumns) nColumns = 1;
827
828 for (i=0; i<nBufSize; i++) {
829 if (!(i%nColumns)) {
830 xml += blanks;
831 }
832 else {
833 xml += " ";
834 }
835
836 switch (Tsig) {
838 switch (nType) {
839 case icConvert8Bit:
840 default:
841 sprintf(str, "%u", (icUInt8Number)buf[i]);
842 break;
843
844 case icConvert16Bit:
845 sprintf(str, "%u", (icUInt16Number)((icFloatNumber)buf[i] * 65535.0 / 255.0 + 0.5));
846 break;
847
848 case icConvertFloat:
849 sprintf(str, icXmlFloatFmt, (icFloatNumber)buf[i] / 255.0);
850 break;
851 }
852 break;
853
855 switch (nType) {
856 case icConvert8Bit:
857 sprintf(str, "%u", (icUInt16Number)((icFloatNumber)buf[i] * 255.0 / 65535.0 + 0.5));
858 break;
859
860 case icConvert16Bit:
861 default:
862 sprintf(str, "%u", (icUInt16Number)buf[i]);
863 break;
864
865 case icConvertFloat:
866 sprintf(str, icXmlFloatFmt, (icFloatNumber)buf[i] / 65535.0);
867 break;
868 }
869 break;
870
872 sprintf(str, "%u", (icUInt32Number)buf[i]);
873 break;
874
876 // unused
877 break;
878
882 switch (nType) {
883 case icConvert8Bit:
884 sprintf(str, "%u", (icUInt8Number)(buf[i] * 255.0 + 0.5));
885 break;
886
887 case icConvert16Bit:
888 sprintf(str, "%u", (icUInt16Number)(buf[i] * 65535.0 + 0.5));
889 break;
890
891 case icConvertFloat:
892 default:
893 sprintf(str, icXmlFloatFmt, (icFloatNumber)buf[i]);
894 }
895 break;
896 }
897 xml += str;
898 if (i%nColumns == nColumns-1) {
899 xml += "\n";
900 }
901 }
902
903 if (i%nColumns) {
904 xml += "\n";
905 }
906
907 return true;
908}
float icFloatNumber
All floating point operations/variables in IccProfLib use the icFloatNumber data type.
Definition IccDefs.h:100
#define icSigFloatArrayType
Definition IccUtilXml.h:173
@ icConvert8Bit
@ icConvertFloat
@ icConvert16Bit
#define icXmlFloatFmt
@ icSigUInt16ArrayType
unsigned int icUInt32Number
unsigned char icUInt8Number
Number definitions.
unsigned short icUInt16Number
@ icSigUInt8ArrayType
@ icSigFloat64ArrayType
@ icSigUInt64ArrayType
@ icSigFloat32ArrayType
@ icSigUInt32ArrayType

References icConvert16Bit, icConvert8Bit, icConvertFloat, icSigFloat32ArrayType, icSigFloat64ArrayType, icSigFloatArrayType, icSigUInt16ArrayType, icSigUInt32ArrayType, icSigUInt64ArrayType, icSigUInt8ArrayType, and icXmlFloatFmt.

Referenced by CIccFormulaCurveSegmentXml::ToXml(), CIccSampledCurveSegmentXml::ToXml(), CIccSinglSampledeCurveXml::ToXml(), CIccTagXmlGamutBoundaryDesc::ToXml(), CIccTagXmlSparseMatrixArray::ToXml(), and CIccXmlToneMapFunc::ToXml().

+ Here is the caller graph for this function:

◆ GetBuf()

◆ GetSize()

◆ ParseArray() [1/2]

template<class T , icTagTypeSignature Tsig>
bool CIccXmlArrayType< T, Tsig >::ParseArray ( T * buf,
icUInt32Number nBufSize,
xmlNode * pNode )
static

Definition at line 1034 of file IccUtilXml.cpp.

1035{
1037 if (Tsig==icSigFloatArrayType) {
1038 n = icXmlNodeCount(pNode, "f");
1039
1040 if (!n) {
1041 if (pNode->type!=XML_TEXT_NODE || !pNode->content)
1042 return false;
1043
1044 n = ParseTextCount((const char*)pNode->content);
1045 if (!n || n>nSize)
1046 return false;
1047
1048 ParseText(pBuf, n, (const char*)pNode->content);
1049 }
1050 else {
1051 if (n>nSize)
1052 return false;
1053
1055 for (i=0; i<nSize && pNode; pNode = pNode->next) {
1056 if (pNode->type == XML_ELEMENT_NODE &&
1057 !icXmlStrCmp(pNode->name, "f") &&
1058 pNode->children &&
1059 pNode->children->content) {
1060 float f;
1061 sscanf((const char *)(pNode->children->content), "%f", &f);
1062 pBuf[i] = (T)f;
1063 i++;
1064 }
1065 }
1066 }
1067 }
1068 else {
1069 n = icXmlNodeCount(pNode, "n");
1070
1071 if (!n) {
1072 if (pNode->type!=XML_TEXT_NODE || !pNode->content)
1073 return false;
1074
1075 n = ParseTextCount((const char *)pNode->content);
1076 if (!n || n>nSize)
1077 return false;
1078
1079 n = ParseText(pBuf, n, (const char *)pNode->content);
1080 }
1081 else {
1082 if (n>nSize)
1083 return false;
1084
1086 for (i=0; i<nSize && pNode; pNode = pNode->next) {
1087 if (pNode->type == XML_ELEMENT_NODE &&
1088 !icXmlStrCmp(pNode->name, "n") &&
1089 pNode->children &&
1090 pNode->children->content) {
1091 pBuf[i] = (T)atol((const char *)(pNode->children->content));
1092 i++;
1093 }
1094 }
1095 }
1096 }
1097 return nSize==n;
1098}
icUInt32Number icXmlNodeCount(xmlNode *pNode, const char *szNodeName)
#define icXmlStrCmp(x, y)
Definition IccUtilXml.h:134
icUInt32Number ParseText(T *pBuf, icUInt32Number nSize, const char *szText)
static icUInt32Number ParseTextCount(const char *szText)

References icSigFloatArrayType, icXmlNodeCount(), and icXmlStrCmp.

Referenced by icCLutFromXml(), CIccFormulaCurveSegmentXml::ParseXml(), CIccMpeXmlEmissionCLUT::ParseXml(), CIccMpeXmlEmissionMatrix::ParseXml(), CIccMpeXmlEmissionObserver::ParseXml(), CIccMpeXmlInvEmissionMatrix::ParseXml(), CIccMpeXmlMatrix::ParseXml(), CIccMpeXmlReflectanceCLUT::ParseXml(), CIccMpeXmlReflectanceObserver::ParseXml(), CIccSampledCurveSegmentXml::ParseXml(), CIccSinglSampledeCurveXml::ParseXml(), CIccTagXmlColorantOrder::ParseXml(), CIccTagXmlCurve::ParseXml(), CIccTagXmlFixedNum< T, Tsig >::ParseXml(), CIccTagXmlGamutBoundaryDesc::ParseXml(), CIccTagXmlNamedColor2::ParseXml(), CIccTagXmlParametricCurve::ParseXml(), and CIccXmlToneMapFunc::ParseXml().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ParseArray() [2/2]

template<class T , icTagTypeSignature Tsig>
bool CIccXmlArrayType< T, Tsig >::ParseArray ( xmlNode * pNode)

Definition at line 755 of file IccUtilXml.cpp.

756{
757 char scanType[2] = {0};
758 scanType[0] = (Tsig == icSigFloatArrayType ? 'f' : 'n');
759 scanType[1] = 0;
760
761 icUInt32Number n = icXmlNodeCount(pNode, scanType);
762
763 if (n) {
764 if (!SetSize(n))
765 return false;
766 return ParseArray(m_pBuf, m_nSize, pNode);
767 }
768
769 for ( ;pNode && pNode->type!= XML_TEXT_NODE; pNode=pNode->next);
770
771 if (!pNode || !pNode->content)
772 return false;
773
774 n = ParseTextCount((const char*)pNode->content);
775
776 if (!n || !SetSize(n))
777 return false;
778
779 return ParseArray(m_pBuf, m_nSize, pNode);
780}
bool SetSize(icUInt32Number nSize)
static bool ParseArray(T *buf, icUInt32Number nBufSize, xmlNode *pNode)

References icSigFloatArrayType, and icXmlNodeCount().

+ Here is the call graph for this function:

◆ ParseText() [1/2]

template<class T , icTagTypeSignature Tsig>
static icUInt32Number CIccXmlArrayType< T, Tsig >::ParseText ( T * buf,
icUInt32Number nBufSize,
const char * szText )
static

◆ ParseText() [2/2]

template<class T , icTagTypeSignature Tsig>
icUInt32Number CIccXmlArrayType< T, Tsig >::ParseText ( T * pBuf,
icUInt32Number nSize,
const char * szText )

Definition at line 56 of file TestParseText.cpp.

56 {
57 icUInt32Number n = 0;
58 char num[256] = {0};
59 int b = 0;
60 bool bInNum = false;
61
62 while (*szText && n < nSize) {
63 if (icIsNumChar(*szText)) {
64 if (!bInNum) {
65 bInNum = true;
66 b = 0;
67 }
68 if (b < sizeof(num) - 2) {
69 num[b++] = *szText;
70 }
71 } else {
72 if (bInNum) {
73 num[b] = '\0';
74 pBuf[n++] = (T)atof(num);
75 bInNum = false;
76 }
77 }
78 szText++;
79 }
80
81 if (bInNum && n < nSize) {
82 num[b] = '\0';
83 pBuf[n++] = (T)atof(num);
84 }
85
86 return n;
87}
bool icIsNumChar(char c)

References icIsNumChar().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ParseTextArray() [1/2]

template<class T , icTagTypeSignature Tsig>
bool CIccXmlArrayType< T, Tsig >::ParseTextArray ( const char * szText)

Definition at line 783 of file IccUtilXml.cpp.

784{
785 icUInt32Number n = ParseTextCount(szText);
786
787 if (n) {
788 if (!SetSize(n))
789 return false;
790
791 return ParseText(m_pBuf, m_nSize, szText)==m_nSize;
792 }
793
794 return false;
795}

Referenced by CIccTagXmlSparseMatrixArray::ParseXml(), and CIccTagXmlSpectralViewingConditions::ParseXml().

+ Here is the caller graph for this function:

◆ ParseTextArray() [2/2]

template<class T , icTagTypeSignature Tsig>
bool CIccXmlArrayType< T, Tsig >::ParseTextArray ( xmlNode * pNode)

Definition at line 798 of file IccUtilXml.cpp.

799{
800 if (pNode->children && pNode->children->type==XML_TEXT_NODE) {
801 return ParseTextArray((const char*)pNode->children->content);
802 }
803 return false;
804}
bool ParseTextArray(const char *szText)

◆ ParseTextArrayNum()

template<class T , icTagTypeSignature Tsig>
bool CIccXmlArrayType< T, Tsig >::ParseTextArrayNum ( const char * szText,
icUInt32Number num,
std::string & parseStr )

Definition at line 807 of file IccUtilXml.cpp.

808{
809 icUInt32Number n = ParseTextCountNum(szText, num, parseStr);
810 if (n) {
811 if (!SetSize(n))
812 return false;
813 return ParseText(m_pBuf, m_nSize, szText)==m_nSize;
814 }
815
816 return false;
817}
static icUInt32Number ParseTextCountNum(const char *szText, icUInt32Number num, std::string &parseStr)

Referenced by icCLutFromXml(), CIccSampledCurveSegmentXml::ParseXml(), CIccSinglSampledeCurveXml::ParseXml(), and CIccTagXmlCurve::ParseXml().

+ Here is the caller graph for this function:

◆ ParseTextCount()

template<class T , icTagTypeSignature Tsig>
icUInt32Number CIccXmlArrayType< T, Tsig >::ParseTextCount ( const char * szText)
static

Definition at line 961 of file IccUtilXml.cpp.

962{
963 icUInt32Number n = 0;
964 bool bInNum = false;
965
966 while (*szText) {
967 if (icIsNumChar(*szText)) {
968 if (!bInNum) {
969 bInNum = true;
970 }
971 }
972 else if (bInNum && !strncmp(szText, "#QNAN", 5)) { //Handle 1.#QNAN000 (non a number)
973 szText+=4;
974 }
975 else if (bInNum) {
976 n++;
977 bInNum = false;
978 }
979 szText++;
980 }
981 if (bInNum) {
982 n++;
983 }
984
985 return n;
986}

References icIsNumChar().

+ Here is the call graph for this function:

◆ ParseTextCountNum()

template<class T , icTagTypeSignature Tsig>
icUInt32Number CIccXmlArrayType< T, Tsig >::ParseTextCountNum ( const char * szText,
icUInt32Number num,
std::string & parseStr )
static

Definition at line 922 of file IccUtilXml.cpp.

923{
924 icUInt32Number n = 0;
925 bool bInNum = false;
926 //icUInt32Number count = 1;
927
928 //while (*szText) {
929 for (icUInt32Number i=0; i<num; i++) {
930 if (icIsNumChar(*szText)) {
931 if (!bInNum) {
932 bInNum = true;
933 }
934 }
935 else if (bInNum && !strncmp(szText, "#QNAN", 5)) { //Handle 1.#QNAN000 (non a number)
936 i+=4;
937 szText+=4;
938 }
939 // an invalid character is encountered (not digit and not space)
940 else if (!isspace(*szText) && i <= num ){
941 char line[100];
942 sprintf(line, "Data '%c' in position %d is not a number. ", *szText, i);
943 parseStr += line;
944 return false;
945 }
946 else if (bInNum) { //char is a space
947 n++;
948 bInNum = false;
949 }
950 szText++;
951 //count++;
952 }
953 if (bInNum) {
954 n++;
955 }
956
957 return n;
958}

References icIsNumChar().

+ Here is the call graph for this function:

◆ SetSize()

template<class T , icTagTypeSignature Tsig>
bool CIccXmlArrayType< T, Tsig >::SetSize ( icUInt32Number nSize)

Definition at line 1102 of file IccUtilXml.cpp.

1103{
1104 if (m_pBuf) {
1105 free(m_pBuf);
1106 }
1107 m_pBuf = (T*)malloc(nSize * sizeof(T));
1108 if (!m_pBuf) {
1109 m_nSize = 0;
1110 return false;
1111 }
1112 m_nSize = nSize;
1113
1114 return true;
1115}

Referenced by icXmlParseTextString(), CIccTagXmlZipUtf8Text::ParseXml(), and CIccTagXmlZipXml::ParseXml().

+ Here is the caller graph for this function:

Member Data Documentation

◆ m_nSize

template<class T , icTagTypeSignature Tsig>
icUInt32Number CIccXmlArrayType< T, Tsig >::m_nSize

Definition at line 47 of file TestParseText.cpp.

Referenced by CIccXmlArrayType< T, Tsig >::GetSize().

◆ m_pBuf

template<class T , icTagTypeSignature Tsig>
T * CIccXmlArrayType< T, Tsig >::m_pBuf

The documentation for this class was generated from the following files: