37 "the file " << file <<
" contains OKS time data stored in deprecated format \'" << data <<
"\'. Please refresh it using an oks application. Support for such format will be removed in a future release.",
52 data.
TIME = *
reinterpret_cast<uint64_t*
>(&t);
57 return boost::gregorian::date(boost::gregorian::gregorian_calendar::from_day_number(data.DATE));
62 return *
reinterpret_cast<boost::posix_time::ptime*
>(
const_cast<uint64_t*
>(&data.TIME));
68 for(OksData::List::const_iterator i = dlist.begin(); i != dlist.end(); ++i) {
78 if(&l1 == &l2)
return true;
80 size_t l1Lenght = l1.size();
81 size_t l2Lenght = l2.size();
83 if(!l1Lenght && !l2Lenght)
return true;
84 if(l1Lenght != l2Lenght)
return false;
91 for(;i1 != l1.end(); ++i1, ++i2) {
95 if( !d1 && !d2 )
return true;
96 if( !d1 || !d2 )
return false;
100 (d1->type == d2->type) &&
103 (!d1->data.OBJECT && !d2->data.OBJECT) ||
105 (d1->data.OBJECT && d2->data.OBJECT) &&
106 (d1->data.OBJECT->GetClass()->get_name() == d2->data.OBJECT->GetClass()->get_name()) &&
107 (d1->data.OBJECT->GetId() == d2->data.OBJECT->GetId())
157 return ( (d == *
this) ?
false :
true );
164 const char * fname =
"OksData::operator[<|<=|>|>=](const OksData&) const";
165 const char * h3 =
"Can't compare ";
201#define CMP_OBJ( OP, c1, c2, id1, id2 ) (c1 OP c2) || (!(c2 OP c1) && id1 OP id2)
203#define CMP_DATA( OP ) \
205 case string_type: return (*data.STRING OP *d.data.STRING); \
206 case u32_int_type: return (data.U32_INT OP d.data.U32_INT); \
207 case s32_int_type: return (data.S32_INT OP d.data.S32_INT); \
208 case u16_int_type: return (data.U16_INT OP d.data.U16_INT); \
209 case s16_int_type: return (data.S16_INT OP d.data.S16_INT); \
210 case s8_int_type: return (data.S8_INT OP d.data.S8_INT); \
211 case u8_int_type: return (data.U8_INT OP d.data.U8_INT); \
212 case s64_int_type: return (data.S64_INT OP d.data.S64_INT); \
213 case u64_int_type: return (data.U64_INT OP d.data.U64_INT); \
214 case float_type: return (data.FLOAT OP d.data.FLOAT); \
215 case double_type: return (data.DOUBLE OP d.data.DOUBLE); \
216 case bool_type: return (data.BOOL OP d.data.BOOL); \
217 case date_type: return (data.DATE OP d.data.DATE); \
218 case time_type: return (data.TIME OP d.data.TIME); \
219 case enum_type: return (*data.ENUMERATION OP *d.data.ENUMERATION); \
220 case class_type: return (data.CLASS->get_name() OP d.data.CLASS->get_name()); \
224 return CMP_OBJ ( OP, __cn(), d.__cn(), __oid(), d.__oid() ); \
225 default: return false; \
252 if(test_comparable(
type, d.type) ==
false)
return false;
259 if(test_comparable(
type, d.type) ==
false)
return false;
266 if(test_comparable(
type, d.type) ==
false)
return false;
273 if(test_comparable(
type, d.type) ==
false)
return false;
286 for(List::iterator i = d.data.LIST->begin(); i != d.data.LIST->end(); ++i) {
326 for(OksData::List::iterator i = d.data.LIST->begin(); i != d.data.LIST->end(); ++i) {
328 if((*i) != d.data.LIST->back()) s <<
", ";
334 s <<
'\"' << *(d.data.STRING) <<
'\"';
339 s <<
'[' << d.data.OBJECT->GetId() <<
'@' << d.data.OBJECT->GetClass()->get_name() <<
']';
346 s <<
'#' <<
'[' << *d.data.UID2.object_id <<
'@' << *d.data.UID2.class_id <<
']';
350 s <<
'#' <<
'[' << *d.data.UID.object_id <<
'@' << d.data.UID.class_id->get_name() <<
']';
370 std::streamsize p = s.precision();
371 s.precision(std::numeric_limits< float >::digits10);
377 std::streamsize p = s.precision();
378 s.precision(std::numeric_limits< double >::digits10);
384 s << static_cast<int16_t>(d.data.S8_INT);
388 s << static_cast<uint16_t>(d.data.U8_INT);
400 s << ( (d.data.BOOL ==
true) ?
"true" :
"false" );
404 s << boost::gregorian::to_simple_string(d.date());
408 s << boost::posix_time::to_simple_string(d.time());
412 s <<
'\"' << *(d.data.ENUMERATION) <<
'\"';
416 s <<
'[' << d.data.CLASS->get_name() <<
']';
421 <<
"Can't put to stream \'OksData::unknown_type\'";
436 if(!dlist->empty()) {
468 std::ostringstream s;
473 s <<
'\'' << *d <<
'\'';
474 s <<
" is out of range \'" <<
range <<
'\'';
481 std::ostringstream s;
483 if(value) { s <<
"string \'" << value <<
'\''; }
484 else { s <<
"empty string"; }
486 s <<
" is not a valid value for \'" <<
type <<
"\' type";
488 if(!reason.empty()) s <<
":\n" << reason;
496 std::ostringstream s;
498 s <<
"the string is not a valid value for \'" <<
type <<
"\' type";
500 if(!reason.empty()) s <<
":\n" << reason;
509 if (a->p_range_obj ==
nullptr)
524 if (a->p_range_obj->validate(*
this) ==
false)
526 throw AttributeRangeError(
this, a->get_range());
549 case date_type:
SetFast(boost::gregorian::day_clock::universal_day());
return;
550 case time_type:
SetFast(boost::posix_time::second_clock::universal_time());
return;
551 default:
Clear2();
throw AttributeReadError(
"",
"non-attribute-type",
"internal OKS error");
568 case 1:
data.
BOOL = (*s ==
't' || *s ==
'T' || *s ==
'1');
return;
584 catch(std::exception& ex) {
585 throw AttributeReadError(s,
"enum", ex.what());
588 if(strchr(s,
'-') || strchr(s,
'/')) {
589 SetFast(boost::gregorian::from_simple_string(s));
return;
592 SetFast(boost::gregorian::from_undelimited_string(s));
return;
595 catch(std::exception& ex) {
596 throw AttributeReadError(s,
"date", ex.what());
599 if(strlen(s) == 15 && s[8] ==
'T') {
600 SetFast(boost::posix_time::from_iso_string(s));
return;
603 SetFast(boost::posix_time::time_from_string(s));
return;
606 catch(std::exception& ex) {
607 throw AttributeReadError(s,
"time", ex.what());
609 case class_type:
if(OksClass * c = a->p_class->get_kernel()->find_class(s)) {
613 Clear2();
throw AttributeReadError(s,
"class",
"the value is not a name of valid OKS class");
615 default:
Clear2();
throw AttributeReadError(s,
"non-attribute-type",
"internal OKS error");
622std::list<std::string>
625 std::list<std::string> val;
632 for(OksData::List::const_iterator i = d.data.LIST->begin(); i != d.data.LIST->end(); ++i) {
633 val.push_back((*i)->str());
644 if( !a->get_is_multi_values() ) {
657 while( *s ==
' ' ) s++;
658 if( *s ==
'\0' )
return;
662 while(
str.length() ) {
663 while(
str.length() &&
str[0] ==
' ')
str.erase(0, 1);
664 if( !
str.length() )
return;
666 str[0] ==
'\"' ?
'\"' :
667 str[0] ==
'\'' ?
'\'' :
668 str[0] ==
'`' ?
'`' :
672 if(delimeter !=
',')
str.erase(0, 1);
673 std::string::size_type p =
str.find(delimeter);
676 d->type = a->get_data_type();
679 d->data.STRING =
new OksString(
str, p);
682 std::string token(
str, 0, p);
683 d->data.ENUMERATION = a->get_enum_value(token);
686 std::string token(
str, 0, p);
687 d->SetValue(token.c_str(), a);
694 if(delimeter !=
',') {
696 if( p == std::string::npos )
731 throw std::runtime_error(
"empty numeric value");
744 else if(c ==
' ' || c ==
'\n' || c ==
'\r' || c ==
'\t') {
753 catch(std::exception& ex) {
755 throw BadFileData(std::string(
"failed to read numeric value: ") + ex.what(),
line_no,
line_pos);
760OksData::read(
const ReadFileParams& read_params,
const OksAttribute * a, int32_t num)
776OksData::read(
const ReadFileParams& read_params,
const OksAttribute *a)
778 const char * read_value=
"";
780 OksXmlInputStream& fxs(read_params.s);
783 switch(a->get_data_type()) {
785 read_value =
"quoted string";
787 size_t len = fxs.get_quoted();
789 data.
STRING->assign(fxs.get_xml_token().m_buf, len);
794 data.
STRING =
new OksString(fxs.get_xml_token().m_buf, len);
800 read_value =
"signed 32 bits integer";
801 fxs.get_num_token(
'<');
802 Set(
static_cast<int32_t
>(strtol(fxs.m_cvt_char->m_buf, &__sanity, 0)));
803 if( __builtin_expect((*__sanity != 0 || errno == ERANGE), 0) )
OksXmlInputStream::__throw_strto(
"strtol", __sanity, fxs.m_cvt_char->m_buf, fxs.line_no, fxs.line_pos);
807 read_value =
"unsigned 32 bits integer";
808 fxs.get_num_token(
'<');
809 Set(
static_cast<uint32_t
>(strtoul(fxs.m_cvt_char->m_buf, &__sanity, 0)));
810 if( __builtin_expect((*__sanity != 0 || errno == ERANGE), 0) )
OksXmlInputStream::__throw_strto(
"strtoul", __sanity, fxs.m_cvt_char->m_buf, fxs.line_no, fxs.line_pos);
814 read_value =
"signed 16 bits integer";
815 fxs.get_num_token(
'<');
816 Set(
static_cast<int16_t
>(strtol(fxs.m_cvt_char->m_buf, &__sanity, 0)));
817 if( __builtin_expect((*__sanity != 0 || errno == ERANGE), 0) )
OksXmlInputStream::__throw_strto(
"strtol", __sanity, fxs.m_cvt_char->m_buf, fxs.line_no, fxs.line_pos);
821 read_value =
"unsigned 16 bits integer";
822 fxs.get_num_token(
'<');
823 Set(
static_cast<uint16_t
>(strtoul(fxs.m_cvt_char->m_buf, &__sanity, 0)));
824 if( __builtin_expect((*__sanity != 0 || errno == ERANGE), 0) )
OksXmlInputStream::__throw_strto(
"strtoul", __sanity, fxs.m_cvt_char->m_buf, fxs.line_no, fxs.line_pos);
828 read_value =
"signed 8 bits integer";
829 fxs.get_num_token(
'<');
830 Set(
static_cast<int8_t
>(strtol(fxs.m_cvt_char->m_buf, &__sanity, 0)));
831 if( __builtin_expect((*__sanity != 0 || errno == ERANGE), 0) )
OksXmlInputStream::__throw_strto(
"strtol", __sanity, fxs.m_cvt_char->m_buf, fxs.line_no, fxs.line_pos);
835 read_value =
"unsigned 8 bits integer";
836 fxs.get_num_token(
'<');
837 Set(
static_cast<uint8_t
>(strtoul(fxs.m_cvt_char->m_buf, &__sanity, 0)));
838 if( __builtin_expect((*__sanity != 0 || errno == ERANGE), 0) )
OksXmlInputStream::__throw_strto(
"strtoul", __sanity, fxs.m_cvt_char->m_buf, fxs.line_no, fxs.line_pos);
842 read_value =
"signed 64 bits integer";
843 fxs.get_num_token(
'<');
844 Set(
static_cast<int64_t
>(strtoll(fxs.m_cvt_char->m_buf, &__sanity, 0)));
845 if( __builtin_expect((*__sanity != 0 || errno == ERANGE), 0) )
OksXmlInputStream::__throw_strto(
"strtoll", __sanity, fxs.m_cvt_char->m_buf, fxs.line_no, fxs.line_pos);
849 read_value =
"unsigned 64 bits integer";
850 fxs.get_num_token(
'<');
851 Set(
static_cast<uint64_t
>(strtoull(fxs.m_cvt_char->m_buf, &__sanity, 0)));
852 if( __builtin_expect((*__sanity != 0 || errno == ERANGE), 0) )
OksXmlInputStream::__throw_strto(
"strtoull", __sanity, fxs.m_cvt_char->m_buf, fxs.line_no, fxs.line_pos);
856 read_value =
"float";
857 fxs.get_num_token(
'<');
858 Set(strtof(fxs.m_cvt_char->m_buf, &__sanity));
859 if( __builtin_expect((*__sanity != 0 || errno == ERANGE), 0) )
OksXmlInputStream::__throw_strto(
"strtof", __sanity, fxs.m_cvt_char->m_buf, fxs.line_no, fxs.line_pos);
863 read_value =
"double";
864 fxs.get_num_token(
'<');
865 Set(strtod(fxs.m_cvt_char->m_buf, &__sanity));
866 if( __builtin_expect((*__sanity != 0 || errno == ERANGE), 0) )
OksXmlInputStream::__throw_strto(
"strtod", __sanity, fxs.m_cvt_char->m_buf, fxs.line_no, fxs.line_pos);
870 read_value =
"boolean";
871 fxs.get_num_token(
'<');
872 Set(
static_cast<bool>(strtol(fxs.m_cvt_char->m_buf, &__sanity, 0)));
873 if( __builtin_expect((*__sanity != 0 || errno == ERANGE), 0) )
OksXmlInputStream::__throw_strto(
"strtol", __sanity, fxs.m_cvt_char->m_buf, fxs.line_no, fxs.line_pos);
877 read_value =
"quoted date string";
879 size_t len = fxs.get_quoted();
885 read_value =
"quoted time string";
887 size_t len = fxs.get_quoted();
893 read_value =
"quoted enum string";
895 size_t len = fxs.get_quoted();
896 SetE(fxs.get_xml_token().m_buf, len, a);
901 read_value =
"two quoted class-name / object-id strings";
902 Set(
new OksString(),
new OksString());
904 size_t len = fxs.get_quoted();
906 len = fxs.get_quoted();
912 read_value =
"quoted class-type string";
915 SetValue(fxs.get_xml_token().m_buf, a);
921 std::ostringstream s;
922 s <<
"Unknown attribute type \"" << (int)a->get_data_type() <<
"\" (line " << fxs.get_line_no() <<
", char " << fxs.get_line_pos() <<
')';
923 throw std::runtime_error( s.str().c_str() );
928 throw FailedRead(read_value, e);
930 catch (std::exception & e) {
931 throw FailedRead(read_value, e.what());
937OksData::read(
const OksAttribute *a,
const OksXmlValue& value)
939 const char * read_value=
"";
943 switch(a->get_data_type()) {
947 data.
STRING->assign(value.buf(), value.len());
952 data.
STRING =
new OksString(value.buf(), value.len());
958 read_value =
"signed 32 bits integer";
959 Set(
static_cast<int32_t
>(strtol(value.buf(), &__sanity, 0)));
960 if( __builtin_expect((*__sanity != 0 || errno == ERANGE), 0) )
OksXmlInputStream::__throw_strto(
"strtol", __sanity, value.buf(), value.line_no(), value.line_pos());
964 read_value =
"unsigned 32 bits integer";
965 Set(
static_cast<uint32_t
>(strtoul(value.buf(), &__sanity, 0)));
966 if( __builtin_expect((*__sanity != 0 || errno == ERANGE), 0) )
OksXmlInputStream::__throw_strto(
"strtoul", __sanity, value.buf(), value.line_no(), value.line_pos());
970 read_value =
"signed 16 bits integer";
971 Set(
static_cast<int16_t
>(strtol(value.buf(), &__sanity, 0)));
972 if( __builtin_expect((*__sanity != 0 || errno == ERANGE), 0) )
OksXmlInputStream::__throw_strto(
"strtol", __sanity, value.buf(), value.line_no(), value.line_pos());
976 read_value =
"unsigned 16 bits integer";
977 Set(
static_cast<uint16_t
>(strtoul(value.buf(), &__sanity, 0)));
978 if( __builtin_expect((*__sanity != 0 || errno == ERANGE), 0) )
OksXmlInputStream::__throw_strto(
"strtoul", __sanity, value.buf(), value.line_no(), value.line_pos());
982 read_value =
"signed 8 bits integer";
983 Set(
static_cast<int8_t
>(strtol(value.buf(), &__sanity, 0)));
984 if( __builtin_expect((*__sanity != 0 || errno == ERANGE), 0) )
OksXmlInputStream::__throw_strto(
"strtol", __sanity, value.buf(), value.line_no(), value.line_pos());
988 read_value =
"unsigned 8 bits integer";
989 Set(
static_cast<uint8_t
>(strtoul(value.buf(), &__sanity, 0)));
990 if( __builtin_expect((*__sanity != 0 || errno == ERANGE), 0) )
OksXmlInputStream::__throw_strto(
"strtoul", __sanity, value.buf(), value.line_no(), value.line_pos());
994 read_value =
"signed 64 bits integer";
995 Set(
static_cast<int64_t
>(strtoll(value.buf(), &__sanity, 0)));
996 if( __builtin_expect((*__sanity != 0 || errno == ERANGE), 0) )
OksXmlInputStream::__throw_strto(
"strtoll", __sanity, value.buf(), value.line_no(), value.line_pos());
1000 read_value =
"unsigned 64 bits integer";
1001 Set(
static_cast<uint64_t
>(strtoull(value.buf(), &__sanity, 0)));
1002 if( __builtin_expect((*__sanity != 0 || errno == ERANGE), 0) )
OksXmlInputStream::__throw_strto(
"strtoull", __sanity, value.buf(), value.line_no(), value.line_pos());
1006 read_value =
"float";
1007 Set(strtof(value.buf(), &__sanity));
1008 if( __builtin_expect((*__sanity != 0 || errno == ERANGE), 0) )
OksXmlInputStream::__throw_strto(
"strtof", __sanity, value.buf(), value.line_no(), value.line_pos());
1012 read_value =
"double";
1013 Set(strtod(value.buf(), &__sanity));
1014 if( __builtin_expect((*__sanity != 0 || errno == ERANGE), 0) )
OksXmlInputStream::__throw_strto(
"strtod", __sanity, value.buf(), value.line_no(), value.line_pos());
1018 read_value =
"boolean";
1019 Set(
static_cast<bool>(strtol(value.buf(), &__sanity, 0)));
1020 if( __builtin_expect((*__sanity != 0 || errno == ERANGE), 0) )
OksXmlInputStream::__throw_strto(
"strtol", __sanity, value.buf(), value.line_no(), value.line_pos());
1024 read_value =
"quoted date string";
1029 read_value =
"quoted time string";
1034 read_value =
"quoted enum string";
1035 SetE(value.buf(), value.len(), a);
1039 read_value =
"two quoted class-name / object-id strings";
1041 std::ostringstream s;
1042 s <<
"Unexpected uid2 type at (line " << value.line_no() <<
", char " << value.line_pos() <<
')';
1043 throw std::runtime_error( s.str().c_str() );
1048 read_value =
"quoted class-type string";
1056 std::ostringstream s;
1057 s <<
"Unknown attribute type \"" << (int)a->get_data_type() <<
"\" (line " << value.line_no() <<
", char " << value.line_pos() <<
')';
1058 throw std::runtime_error( s.str().c_str() );
1063 throw FailedRead(read_value, e);
1065 catch (std::exception & e) {
1066 throw FailedRead(read_value, e.what());
1071OksData::read(
const OksAttribute *a,
const ReadFileParams& read_params)
1081 const char * tag_start = read_params.s.get_tag_start();
1090 OksXmlAttribute attr(read_params.s);
1094 OksXmlValue value(read_params.s.get_value(attr.p_value_len));
1099 std::ostringstream s;
1100 s <<
"Unexpected attribute \"" << attr.name() <<
"\" instead of \"" <<
OksObject::value_xml_attribute <<
"\" (line " << read_params.s.get_line_no() <<
", char " << read_params.s.get_line_pos() <<
')';
1101 throw std::runtime_error(s.str().c_str());
1105 OksXmlAttribute attr(read_params.s);
1107 if (
cmp_str1(attr.name(),
"/") ==
false)
1109 std::ostringstream s;
1110 s <<
"Unexpected tag \"" << attr.name() <<
"\" instead of close tag (line " << read_params.s.get_line_no() <<
", char " << read_params.s.get_line_pos() <<
')';
1111 throw std::runtime_error(s.str().c_str());
1117 std::ostringstream s;
1118 s <<
"Unexpected tag \"" << tag_start <<
"\" (line " << read_params.s.get_line_no() <<
", char " << read_params.s.get_line_pos() <<
')';
1119 throw std::runtime_error(s.str().c_str());
1124 throw FailedRead(
"multi-value", e);
1126 catch (std::exception & e)
1128 throw FailedRead(
"multi-value", e.what());
1133OksData::read(
const ReadFileParams& read_params,
const OksRelationship * r, int32_t num)
1138 else if( __builtin_expect((!
data.
LIST->empty()), 0) ) {
1146 if( __builtin_expect((d->type ==
OksData::uid2_type && d->data.UID2.class_id->empty()), 0) )
continue;
1154OksData::read(
const ReadFileParams& read_params,
const OksRelationship * r)
1156 const OksClass * rel_class(r->p_class_type);
1157 OksString * class_id(0);
1158 const OksClass * c(0);
1159 OksXmlInputStream& fxs(read_params.s);
1165 size_t len = fxs.get_quoted();
1167 if( __builtin_expect((len > 0), 1) ) {
1168 if( __builtin_expect((!read_params.alias_table), 1) ) {
1169 if( __builtin_expect((rel_class != 0), 1) ) {
1170 c = rel_class->get_kernel()->find_class(fxs.get_xml_token().m_buf);
1173 if( __builtin_expect((c == 0), 0) ) {
1174 class_id =
new OksString(fxs.get_xml_token().m_buf, len);
1178 const char * class_name_str(fxs.get_xml_token().m_buf);
1180 if(class_name_str[0] ==
'@') {
1184 c = ( rel_class ? rel_class->get_kernel()->find_class(class_name_str) : 0 );
1187 read_params.alias_table->add_value(0, c);
1190 read_params.alias_table->add_value(
new OksString(class_name_str, len), 0);
1195 if(
const OksAliasTable::Value * value = read_params.alias_table->get(class_name_str)) {
1199 : rel_class->get_kernel()->find_class(*value->class_name)
1203 Oks::warning_msg(
"OksData::read(const ReadFileParams&, const OksRelationship*")
1204 <<
" Can't find alias for class \'" << class_name_str <<
"\'\n"
1205 " Possibly data file has been saved in old format\n";
1207 c = rel_class->get_kernel()->find_class(class_name_str);
1213 class_id =
new OksString(class_name_str, len);
1221 len = fxs.get_quoted();
1223 if( __builtin_expect((c == 0), 0) ) {
1225 Set(class_id,
new OksString(fxs.get_xml_token().m_buf, len));
1236 std::string& obj_id((
const_cast<ReadFileParams&
>(read_params)).tmp);
1237 obj_id.assign(fxs.get_xml_token().m_buf, len);
1241 Set(c,
new OksString(obj_id));
1248 read_params.owner->OksObject::check_class_type(r, c);
1250 obj->add_RCR(read_params.owner, r);
1253 if(class_id)
delete class_id;
1254 throw FailedRead(
"relationship value", ex);
1256 catch (std::exception & ex) {
1257 if(class_id)
delete class_id;
1258 throw FailedRead(
"relationship value", ex.what());
1269OksData::read(
const OksRelationship * r,
const OksXmlRelValue& value)
1273 if (__builtin_expect((value.m_class ==
nullptr), 0))
1275 if (value.m_class_id)
1277 Set(value.m_class_id,
new OksString(value.m_value.buf(), value.m_value.len()));
1278 value.m_class_id =
nullptr;
1288 OksObject *
obj = value.m_class->get_object(value.m_value.buf());
1292 Set(value.m_class,
new OksString(value.m_value.buf(), value.m_value.len()));
1298 value.m_file_params.owner->OksObject::check_class_type(r, value.m_class);
1300 obj->add_RCR(value.m_file_params.owner, r);
1304 if (value.m_class_id)
1305 delete value.m_class_id;
1306 throw FailedRead(
"relationship value", ex);
1308 catch (std::exception & ex)
1310 if (value.m_class_id)
1311 delete value.m_class_id;
1312 throw FailedRead(
"relationship value", ex.what());
1321OksData::read(
const OksRelationship *r,
const ReadFileParams& read_params)
1331 const char * tag_start = read_params.s.get_tag_start();
1339 OksXmlRelValue value(read_params);
1343 OksXmlAttribute attr(read_params.s);
1352 value.m_class = read_params.owner->uid.class_id->get_kernel()->find_class(attr.value());
1353 if( __builtin_expect((value.m_class ==
nullptr && attr.value_len() > 0), 0) ) {
1354 value.m_class_id =
new OksString(attr.value(), attr.value_len());
1358 value.m_value = read_params.s.get_value(attr.p_value_len);
1361 read_params.s.throw_unexpected_attribute(attr.name());
1364 if(value.is_empty() ==
false)
1369 if( __builtin_expect((d->type ==
OksData::uid2_type && d->data.UID2.class_id->empty()), 0) )
continue;
1376 throw FailedRead(
"multi-value relationship", e);
1378 catch (std::exception & e) {
1379 throw FailedRead(
"multi-value relationship", e.what());
1384 std::ostringstream s;
1385 s <<
"Unexpected tag \"" << tag_start <<
"\" (line " << read_params.s.get_line_no() <<
", char " << read_params.s.get_line_pos() <<
')';
1386 throw std::runtime_error(s.str().c_str());
1391 throw FailedRead(
"multi-value", e);
1393 catch (std::exception & e)
1395 throw FailedRead(
"multi-value", e.what());
1411 if(put_number) xmls.put_value((
unsigned long)
data.
LIST->size());
1420 (*i)->WriteTo(xmls, put_number);
1430 if(put_number) xmls.put_raw(
'0');
1456 std::ostream& s = xmls.get_stream();
1457 std::streamsize p = s.precision();
1458 s.precision(std::numeric_limits< float >::digits10);
1464 std::ostream& s = xmls.get_stream();
1465 std::streamsize p = s.precision();
1466 s.precision(std::numeric_limits< double >::digits10);
1472 xmls.put_value(
static_cast<int16_t
>(
data.
S8_INT));
1476 xmls.put_value(
static_cast<uint16_t
>(
data.
U8_INT));
1488 xmls.put_value((
short)(
data.
BOOL));
1492 xmls.put_quoted(boost::gregorian::to_iso_string(
date()).c_str());
1496 xmls.put_quoted(boost::posix_time::to_iso_string(
time()).c_str());
1512 <<
"Can't write \'" << (
type ==
unknown_type ?
"unknown" :
"relationship") <<
"_type\'\n";
1543 std::ostream& s = xmls.get_stream();
1544 std::streamsize p = s.precision();
1545 s.precision(std::numeric_limits< float >::digits10);
1551 std::ostream& s = xmls.get_stream();
1552 std::streamsize p = s.precision();
1553 s.precision(std::numeric_limits< double >::digits10);
1559 xmls.put_value(
static_cast<int16_t
>(
data.
S8_INT));
1563 xmls.put_value(
static_cast<uint16_t
>(
data.
U8_INT));
1575 xmls.put_value((
short)(
data.
BOOL));
1579 xmls.put(boost::gregorian::to_iso_string(
date()).c_str());
1583 xmls.put(boost::posix_time::to_iso_string(
time()).c_str());
1595 throw std::runtime_error(
"internal error: call OksData::WriteTo() on list");
1602 <<
"Can't write \'" << (
type ==
unknown_type ?
"unknown" :
"relationship") <<
"_type\'\n";
1614OksData::WriteTo(OksXmlOutputStream& xmls, OksKernel *k, OksAliasTable *alias_table,
bool ,
bool put_number)
const
1616 const char * fname =
"WriteTo(OksXmlOutputStream&, ...)";
1618 static std::string emptyName(
"");
1620 const std::string * class_name = 0;
1621 const std::string * object_id = 0;
1630 class_name = object_id = &emptyName;
1636 if(put_number) xmls.put_value((
unsigned long)
data.
LIST->size());
1646 (*i)->WriteTo(xmls, k, alias_table,
false, put_number);
1655 if(put_number) xmls.put_raw(
'0');
1672 <<
"Can't write \'" << (
type ==
unknown_type ?
"unknown" :
"attribute") <<
"_type\'\n";
1677 if(!class_name->empty()) {
1682 xmls.put_quoted(class_name->c_str());
1689 const OksAliasTable::Value *value = alias_table->get(
static_cast<const OksString *
>(class_name));
1693 xmls.put_quoted(value->class_name->c_str());
1697 alias_table->add_key(
static_cast<OksString *
>(
const_cast<std::string *
>(class_name)));
1699 std::string s(*class_name);
1701 xmls.put_quoted(s.c_str());
1707 xmls.put_quoted(
"");
1711 xmls.put_quoted(object_id->c_str());
1727 to->data.LIST->push_back(item);
1737 else if(dd->type ==
OksData::uid_type) item->Set(dd->data.UID.class_id, *dd->data.UID.object_id);
1738 else if(dd->type ==
OksData::uid2_type) item->Set(*dd->data.UID2.class_id, *dd->data.UID2.object_id);
1740 to->data.LIST->push_back(item);
1751 else if(from->type ==
OksData::uid_type)
to->Set(from->data.UID.class_id, *from->data.UID.object_id);
1752 else if(from->type ==
OksData::uid2_type)
to->Set(*from->data.UID2.class_id, *from->data.UID2.object_id);
1760 if(a->get_is_multi_values()) {
1766 std::string cvts =
str();
1767 item->ReadFrom(cvts.c_str(), a->get_data_type(), a);
1769 to->data.LIST->push_back(item);
1778 std::string cvts = dd->str();
1779 item->ReadFrom(cvts.c_str(), a->get_data_type(), a);
1781 to->data.LIST->push_back(item);
1790 if(from) cvts = from->str();
1791 to->ReadFrom(cvts.c_str(), a->get_data_type(), a);
1797list2str(
const OksData::List * l,
const OksKernel * k,
int base)
1799 std::ostringstream s;
1804 bool is_first =
true;
1806 for(OksData::List::const_iterator i = l->begin(); i != l->end(); ++i) {
1807 std::string s2 = (k ? (*i)->str(k) : (*i)->str(base));
1810 if(is_first ==
false) { s <<
", "; }
1811 else { is_first =
false; }
1830 return list2str(
data.
LIST, kernel, 0);
1833 std::ostringstream s;
1851 std::cerr <<
"ERROR [OksData::str(const OksKernel *)]: wrong use for such data: " << *
this << std::endl;
1868 else if(
type ==
date_type) {
return boost::gregorian::to_simple_string(
date()); }
1869 else if(
type ==
time_type) {
return boost::posix_time::to_simple_string(
time()); }
1873 std::ostringstream s;
1876 s.setf((base == 10 ? std::ios::dec : base == 16 ? std::ios::hex : std::ios::oct), std::ios::basefield );
1877 s.setf(std::ios::showbase);
1914 s.precision(std::numeric_limits< float >::digits10);
1919 s.precision(std::numeric_limits< double >::digits10);
1924 std::cerr <<
"ERROR [OksData::str(int)]: wrong use for such data: " << *
this << std::endl;
1941 if(o->GetClass()->get_kernel()->get_silence_mode() !=
true) {
1942 std::cerr << msg <<
": value of \"" << r->get_name() <<
"\" relationship in object " << o <<
" must be non-null\n";
1947 if(o->GetClass()->get_kernel()->get_silence_mode() !=
true) {
1948 std::cerr << msg <<
": \"" << r->get_name() <<
"\" relationship in object " << o <<
" must contain at least one object\n";
1971 boost::posix_time::ptime
str2time(
const char * value,
size_t len,
const char * file_name)
1973 if(len == 15 && value[8] ==
'T') {
1975 return boost::posix_time::from_iso_string(value);
1977 catch (std::exception& ex) {
1979 throw AttributeReadError(value,
"time", ex.what());
1985 std::ostringstream text;
1986 text << std::setfill(
'0')
1987 << std::setw(4) << t.year()
1988 << std::setw(2) << (t.month() + 1)
1989 << std::setw(2) << t.day()
1991 << std::setw(2) << t.hour()
1992 << std::setw(2) << t.min()
1993 << std::setw(2) << t.sec();
1994 TLOG_DEBUG( 1 ) <<
"parse OKS time: " << t <<
" => " << text.str() ;
1999 Oks::warning_msg(
"oks str2time") <<
"The file is using deprecated OKS time format \"" << value <<
"\"\nPlease refresh it using an oks application\nSupport for such format will be removed in a future release.\n";
2001 return boost::posix_time::from_iso_string(text.str());
2005 throw AttributeReadError(value,
"time", ex);
2007 catch (std::exception& ex) {
2009 throw AttributeReadError(value,
"time", ex.what());
2014 boost::gregorian::date
str2date(
const char * value,
size_t len)
2016 if(len == 8 && value[2] !=
'/' && value[3] !=
'/') {
2018 return boost::gregorian::from_undelimited_string(value);
2020 catch (std::exception& ex) {
2021 throw AttributeReadError(value,
"date", ex.what());
2027 std::ostringstream text;
2028 text << std::setfill(
'0')
2029 << std::setw(4) << t.year()
2030 << std::setw(2) << (t.month() + 1)
2031 << std::setw(2) << t.day();
2032 TLOG_DEBUG( 1 ) <<
"parse OKS date: " << t <<
" => " << text.str() ;
2034 Oks::warning_msg(
"oks str2date") <<
"The file is using deprecated OKS date format \"" << value <<
"\"\nPlease refresh it using an oks application.\nSupport for such format will be removed in a future release.\n";
2036 return boost::gregorian::from_undelimited_string(text.str());
2039 throw AttributeReadError(value,
"date", ex);
2041 catch (std::exception& ex) {
2042 throw AttributeReadError(value,
"date", ex.what());