32 "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.",
47 data.
TIME = *
reinterpret_cast<uint64_t*
>(&t);
52 return boost::gregorian::date(boost::gregorian::gregorian_calendar::from_day_number(data.DATE));
57 return *
reinterpret_cast<boost::posix_time::ptime*
>(
const_cast<uint64_t*
>(&data.TIME));
63 for(OksData::List::const_iterator i = dlist.begin(); i != dlist.end(); ++i) {
73 if(&l1 == &l2)
return true;
75 size_t l1Lenght = l1.size();
76 size_t l2Lenght = l2.size();
78 if(!l1Lenght && !l2Lenght)
return true;
79 if(l1Lenght != l2Lenght)
return false;
86 for(;i1 != l1.end(); ++i1, ++i2) {
90 if( !d1 && !d2 )
return true;
91 if( !d1 || !d2 )
return false;
95 (d1->type == d2->type) &&
98 (!d1->data.OBJECT && !d2->data.OBJECT) ||
100 (d1->data.OBJECT && d2->data.OBJECT) &&
101 (d1->data.OBJECT->GetClass()->get_name() == d2->data.OBJECT->GetClass()->get_name()) &&
102 (d1->data.OBJECT->GetId() == d2->data.OBJECT->GetId())
142 ( (type ==
uid_type) && (d.data.UID.class_id->get_name() ==
data.
UID.class_id->get_name() && *d.data.UID.object_id == *
data.
UID.object_id) ) ||
143 ( (type ==
uid2_type) && (*d.data.UID2.class_id == *
data.
UID2.class_id && *d.data.UID2.object_id == *
data.
UID2.object_id) ) ||
152 return ( (d == *
this) ?
false :
true );
159 const char * fname =
"OksData::operator[<|<=|>|>=](const OksData&) const";
160 const char * h3 =
"Can't compare ";
191 return data.
UID.class_id->get_name();
196#define CMP_OBJ( OP, c1, c2, id1, id2 ) (c1 OP c2) || (!(c2 OP c1) && id1 OP id2)
198#define CMP_DATA( OP ) \
200 case string_type: return (*data.STRING OP *d.data.STRING); \
201 case u32_int_type: return (data.U32_INT OP d.data.U32_INT); \
202 case s32_int_type: return (data.S32_INT OP d.data.S32_INT); \
203 case u16_int_type: return (data.U16_INT OP d.data.U16_INT); \
204 case s16_int_type: return (data.S16_INT OP d.data.S16_INT); \
205 case s8_int_type: return (data.S8_INT OP d.data.S8_INT); \
206 case u8_int_type: return (data.U8_INT OP d.data.U8_INT); \
207 case s64_int_type: return (data.S64_INT OP d.data.S64_INT); \
208 case u64_int_type: return (data.U64_INT OP d.data.U64_INT); \
209 case float_type: return (data.FLOAT OP d.data.FLOAT); \
210 case double_type: return (data.DOUBLE OP d.data.DOUBLE); \
211 case bool_type: return (data.BOOL OP d.data.BOOL); \
212 case date_type: return (data.DATE OP d.data.DATE); \
213 case time_type: return (data.TIME OP d.data.TIME); \
214 case enum_type: return (*data.ENUMERATION OP *d.data.ENUMERATION); \
215 case class_type: return (data.CLASS->get_name() OP d.data.CLASS->get_name()); \
219 return CMP_OBJ ( OP, __cn(), d.__cn(), __oid(), d.__oid() ); \
220 default: return false; \
247 if(test_comparable(type, d.type) ==
false)
return false;
254 if(test_comparable(type, d.type) ==
false)
return false;
261 if(test_comparable(type, d.type) ==
false)
return false;
268 if(test_comparable(type, d.type) ==
false)
return false;
281 for(List::iterator i = d.data.LIST->begin(); i != d.data.LIST->end(); ++i) {
301 data.
UID2.class_id =
new OksString(*d.data.UID2.class_id);
302 data.
UID2.object_id =
new OksString(*d.data.UID2.object_id);
305 data.
UID.class_id = d.data.UID.class_id;
306 data.
UID.object_id =
new OksString(*d.data.UID.object_id);
321 for(OksData::List::iterator i = d.data.LIST->begin(); i != d.data.LIST->end(); ++i) {
323 if((*i) != d.data.LIST->back()) s <<
", ";
329 s <<
'\"' << *(d.data.STRING) <<
'\"';
334 s <<
'[' << d.data.OBJECT->GetId() <<
'@' << d.data.OBJECT->GetClass()->get_name() <<
']';
341 s <<
'#' <<
'[' << *d.data.UID2.object_id <<
'@' << *d.data.UID2.class_id <<
']';
345 s <<
'#' <<
'[' << *d.data.UID.object_id <<
'@' << d.data.UID.class_id->get_name() <<
']';
365 std::streamsize p = s.precision();
366 s.precision(std::numeric_limits< float >::digits10);
372 std::streamsize p = s.precision();
373 s.precision(std::numeric_limits< double >::digits10);
379 s << static_cast<int16_t>(d.data.S8_INT);
383 s << static_cast<uint16_t>(d.data.U8_INT);
395 s << ( (d.data.BOOL ==
true) ?
"true" :
"false" );
399 s << boost::gregorian::to_simple_string(d.date());
403 s << boost::posix_time::to_simple_string(d.time());
407 s <<
'\"' << *(d.data.ENUMERATION) <<
'\"';
411 s <<
'[' << d.data.CLASS->get_name() <<
']';
416 <<
"Can't put to stream \'OksData::unknown_type\'";
431 if(!dlist->empty()) {
463 std::ostringstream s;
468 s <<
'\'' << *d <<
'\'';
469 s <<
" is out of range \'" <<
range <<
'\'';
476 std::ostringstream s;
478 if(value) { s <<
"string \'" << value <<
'\''; }
479 else { s <<
"empty string"; }
481 s <<
" is not a valid value for \'" << type <<
"\' type";
483 if(!reason.empty()) s <<
":\n" << reason;
491 std::ostringstream s;
493 s <<
"the string is not a valid value for \'" << type <<
"\' type";
495 if(!reason.empty()) s <<
":\n" << reason;
504 if (a->p_range_obj ==
nullptr)
519 if (a->p_range_obj->validate(*
this) ==
false)
521 throw AttributeRangeError(
this, a->get_range());
544 case date_type:
SetFast(boost::gregorian::day_clock::universal_day());
return;
545 case time_type:
SetFast(boost::posix_time::second_clock::universal_time());
return;
546 default:
Clear2();
throw AttributeReadError(
"",
"non-attribute-type",
"internal OKS error");
563 case 1:
data.
BOOL = (*s ==
't' || *s ==
'T' || *s ==
'1');
return;
579 catch(std::exception& ex) {
580 throw AttributeReadError(s,
"enum", ex.what());
583 if(strchr(s,
'-') || strchr(s,
'/')) {
584 SetFast(boost::gregorian::from_simple_string(s));
return;
587 SetFast(boost::gregorian::from_undelimited_string(s));
return;
590 catch(std::exception& ex) {
591 throw AttributeReadError(s,
"date", ex.what());
594 if(strlen(s) == 15 && s[8] ==
'T') {
595 SetFast(boost::posix_time::from_iso_string(s));
return;
598 SetFast(boost::posix_time::time_from_string(s));
return;
601 catch(std::exception& ex) {
602 throw AttributeReadError(s,
"time", ex.what());
604 case class_type:
if(OksClass * c = a->p_class->get_kernel()->find_class(s)) {
608 Clear2();
throw AttributeReadError(s,
"class",
"the value is not a name of valid OKS class");
610 default:
Clear2();
throw AttributeReadError(s,
"non-attribute-type",
"internal OKS error");
617std::list<std::string>
620 std::list<std::string> val;
627 for(OksData::List::const_iterator i = d.data.LIST->begin(); i != d.data.LIST->end(); ++i) {
628 val.push_back((*i)->str());
639 if( !a->get_is_multi_values() ) {
652 while( *s ==
' ' ) s++;
653 if( *s ==
'\0' )
return;
657 while(
str.length() ) {
658 while(
str.length() &&
str[0] ==
' ')
str.erase(0, 1);
659 if( !
str.length() )
return;
661 str[0] ==
'\"' ?
'\"' :
662 str[0] ==
'\'' ?
'\'' :
663 str[0] ==
'`' ?
'`' :
667 if(delimeter !=
',')
str.erase(0, 1);
668 std::string::size_type p =
str.find(delimeter);
671 d->type = a->get_data_type();
674 d->data.STRING =
new OksString(
str, p);
677 std::string token(
str, 0, p);
678 d->data.ENUMERATION = a->get_enum_value(token);
681 std::string token(
str, 0, p);
682 d->SetValue(token.c_str(), a);
689 if(delimeter !=
',') {
691 if( p == std::string::npos )
726 throw std::runtime_error(
"empty numeric value");
739 else if(c ==
' ' || c ==
'\n' || c ==
'\r' || c ==
'\t') {
748 catch(std::exception& ex) {
750 throw BadFileData(std::string(
"failed to read numeric value: ") + ex.what(),
line_no,
line_pos);
755OksData::read(
const ReadFileParams& read_params,
const OksAttribute * a, int32_t num)
771OksData::read(
const ReadFileParams& read_params,
const OksAttribute *a)
773 const char * read_value=
"";
775 OksXmlInputStream& fxs(read_params.s);
778 switch(a->get_data_type()) {
780 read_value =
"quoted string";
782 size_t len = fxs.get_quoted();
784 data.
STRING->assign(fxs.get_xml_token().m_buf, len);
789 data.
STRING =
new OksString(fxs.get_xml_token().m_buf, len);
795 read_value =
"signed 32 bits integer";
796 fxs.get_num_token(
'<');
797 Set(
static_cast<int32_t
>(strtol(fxs.m_cvt_char->m_buf, &__sanity, 0)));
798 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);
802 read_value =
"unsigned 32 bits integer";
803 fxs.get_num_token(
'<');
804 Set(
static_cast<uint32_t
>(strtoul(fxs.m_cvt_char->m_buf, &__sanity, 0)));
805 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);
809 read_value =
"signed 16 bits integer";
810 fxs.get_num_token(
'<');
811 Set(
static_cast<int16_t
>(strtol(fxs.m_cvt_char->m_buf, &__sanity, 0)));
812 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);
816 read_value =
"unsigned 16 bits integer";
817 fxs.get_num_token(
'<');
818 Set(
static_cast<uint16_t
>(strtoul(fxs.m_cvt_char->m_buf, &__sanity, 0)));
819 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);
823 read_value =
"signed 8 bits integer";
824 fxs.get_num_token(
'<');
825 Set(
static_cast<int8_t
>(strtol(fxs.m_cvt_char->m_buf, &__sanity, 0)));
826 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);
830 read_value =
"unsigned 8 bits integer";
831 fxs.get_num_token(
'<');
832 Set(
static_cast<uint8_t
>(strtoul(fxs.m_cvt_char->m_buf, &__sanity, 0)));
833 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);
837 read_value =
"signed 64 bits integer";
838 fxs.get_num_token(
'<');
839 Set(
static_cast<int64_t
>(strtoll(fxs.m_cvt_char->m_buf, &__sanity, 0)));
840 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);
844 read_value =
"unsigned 64 bits integer";
845 fxs.get_num_token(
'<');
846 Set(
static_cast<uint64_t
>(strtoull(fxs.m_cvt_char->m_buf, &__sanity, 0)));
847 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);
851 read_value =
"float";
852 fxs.get_num_token(
'<');
853 Set(strtof(fxs.m_cvt_char->m_buf, &__sanity));
854 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);
858 read_value =
"double";
859 fxs.get_num_token(
'<');
860 Set(strtod(fxs.m_cvt_char->m_buf, &__sanity));
861 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);
865 read_value =
"boolean";
866 fxs.get_num_token(
'<');
867 Set(
static_cast<bool>(strtol(fxs.m_cvt_char->m_buf, &__sanity, 0)));
868 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);
872 read_value =
"quoted date string";
874 size_t len = fxs.get_quoted();
880 read_value =
"quoted time string";
882 size_t len = fxs.get_quoted();
888 read_value =
"quoted enum string";
890 size_t len = fxs.get_quoted();
891 SetE(fxs.get_xml_token().m_buf, len, a);
896 read_value =
"two quoted class-name / object-id strings";
897 Set(
new OksString(),
new OksString());
899 size_t len = fxs.get_quoted();
900 data.
UID2.class_id->assign(fxs.get_xml_token().m_buf, len);
901 len = fxs.get_quoted();
902 data.
UID2.object_id->assign(fxs.get_xml_token().m_buf, len);
907 read_value =
"quoted class-type string";
910 SetValue(fxs.get_xml_token().m_buf, a);
916 std::ostringstream s;
917 s <<
"Unknown attribute type \"" << (int)a->get_data_type() <<
"\" (line " << fxs.get_line_no() <<
", char " << fxs.get_line_pos() <<
')';
918 throw std::runtime_error( s.str().c_str() );
923 throw FailedRead(read_value, e);
925 catch (std::exception & e) {
926 throw FailedRead(read_value, e.what());
932OksData::read(
const OksAttribute *a,
const OksXmlValue& value)
934 const char * read_value=
"";
938 switch(a->get_data_type()) {
942 data.
STRING->assign(value.buf(), value.len());
947 data.
STRING =
new OksString(value.buf(), value.len());
953 read_value =
"signed 32 bits integer";
954 Set(
static_cast<int32_t
>(strtol(value.buf(), &__sanity, 0)));
955 if( __builtin_expect((*__sanity != 0 || errno == ERANGE), 0) )
OksXmlInputStream::__throw_strto(
"strtol", __sanity, value.buf(), value.line_no(), value.line_pos());
959 read_value =
"unsigned 32 bits integer";
960 Set(
static_cast<uint32_t
>(strtoul(value.buf(), &__sanity, 0)));
961 if( __builtin_expect((*__sanity != 0 || errno == ERANGE), 0) )
OksXmlInputStream::__throw_strto(
"strtoul", __sanity, value.buf(), value.line_no(), value.line_pos());
965 read_value =
"signed 16 bits integer";
966 Set(
static_cast<int16_t
>(strtol(value.buf(), &__sanity, 0)));
967 if( __builtin_expect((*__sanity != 0 || errno == ERANGE), 0) )
OksXmlInputStream::__throw_strto(
"strtol", __sanity, value.buf(), value.line_no(), value.line_pos());
971 read_value =
"unsigned 16 bits integer";
972 Set(
static_cast<uint16_t
>(strtoul(value.buf(), &__sanity, 0)));
973 if( __builtin_expect((*__sanity != 0 || errno == ERANGE), 0) )
OksXmlInputStream::__throw_strto(
"strtoul", __sanity, value.buf(), value.line_no(), value.line_pos());
977 read_value =
"signed 8 bits integer";
978 Set(
static_cast<int8_t
>(strtol(value.buf(), &__sanity, 0)));
979 if( __builtin_expect((*__sanity != 0 || errno == ERANGE), 0) )
OksXmlInputStream::__throw_strto(
"strtol", __sanity, value.buf(), value.line_no(), value.line_pos());
983 read_value =
"unsigned 8 bits integer";
984 Set(
static_cast<uint8_t
>(strtoul(value.buf(), &__sanity, 0)));
985 if( __builtin_expect((*__sanity != 0 || errno == ERANGE), 0) )
OksXmlInputStream::__throw_strto(
"strtoul", __sanity, value.buf(), value.line_no(), value.line_pos());
989 read_value =
"signed 64 bits integer";
990 Set(
static_cast<int64_t
>(strtoll(value.buf(), &__sanity, 0)));
991 if( __builtin_expect((*__sanity != 0 || errno == ERANGE), 0) )
OksXmlInputStream::__throw_strto(
"strtoll", __sanity, value.buf(), value.line_no(), value.line_pos());
995 read_value =
"unsigned 64 bits integer";
996 Set(
static_cast<uint64_t
>(strtoull(value.buf(), &__sanity, 0)));
997 if( __builtin_expect((*__sanity != 0 || errno == ERANGE), 0) )
OksXmlInputStream::__throw_strto(
"strtoull", __sanity, value.buf(), value.line_no(), value.line_pos());
1001 read_value =
"float";
1002 Set(strtof(value.buf(), &__sanity));
1003 if( __builtin_expect((*__sanity != 0 || errno == ERANGE), 0) )
OksXmlInputStream::__throw_strto(
"strtof", __sanity, value.buf(), value.line_no(), value.line_pos());
1007 read_value =
"double";
1008 Set(strtod(value.buf(), &__sanity));
1009 if( __builtin_expect((*__sanity != 0 || errno == ERANGE), 0) )
OksXmlInputStream::__throw_strto(
"strtod", __sanity, value.buf(), value.line_no(), value.line_pos());
1013 read_value =
"boolean";
1014 Set(
static_cast<bool>(strtol(value.buf(), &__sanity, 0)));
1015 if( __builtin_expect((*__sanity != 0 || errno == ERANGE), 0) )
OksXmlInputStream::__throw_strto(
"strtol", __sanity, value.buf(), value.line_no(), value.line_pos());
1019 read_value =
"quoted date string";
1024 read_value =
"quoted time string";
1029 read_value =
"quoted enum string";
1030 SetE(value.buf(), value.len(), a);
1034 read_value =
"two quoted class-name / object-id strings";
1036 std::ostringstream s;
1037 s <<
"Unexpected uid2 type at (line " << value.line_no() <<
", char " << value.line_pos() <<
')';
1038 throw std::runtime_error( s.str().c_str() );
1043 read_value =
"quoted class-type string";
1051 std::ostringstream s;
1052 s <<
"Unknown attribute type \"" << (int)a->get_data_type() <<
"\" (line " << value.line_no() <<
", char " << value.line_pos() <<
')';
1053 throw std::runtime_error( s.str().c_str() );
1058 throw FailedRead(read_value, e);
1060 catch (std::exception & e) {
1061 throw FailedRead(read_value, e.what());
1066OksData::read(
const OksAttribute *a,
const ReadFileParams& read_params)
1076 const char * tag_start = read_params.s.get_tag_start();
1085 OksXmlAttribute attr(read_params.s);
1089 OksXmlValue value(read_params.s.get_value(attr.p_value_len));
1094 std::ostringstream s;
1095 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() <<
')';
1096 throw std::runtime_error(s.str().c_str());
1100 OksXmlAttribute attr(read_params.s);
1102 if (
cmp_str1(attr.name(),
"/") ==
false)
1104 std::ostringstream s;
1105 s <<
"Unexpected tag \"" << attr.name() <<
"\" instead of close tag (line " << read_params.s.get_line_no() <<
", char " << read_params.s.get_line_pos() <<
')';
1106 throw std::runtime_error(s.str().c_str());
1112 std::ostringstream s;
1113 s <<
"Unexpected tag \"" << tag_start <<
"\" (line " << read_params.s.get_line_no() <<
", char " << read_params.s.get_line_pos() <<
')';
1114 throw std::runtime_error(s.str().c_str());
1119 throw FailedRead(
"multi-value", e);
1121 catch (std::exception & e)
1123 throw FailedRead(
"multi-value", e.what());
1128OksData::read(
const ReadFileParams& read_params,
const OksRelationship * r, int32_t num)
1130 if( __builtin_expect((type !=
list_type), 0) ) {
1133 else if( __builtin_expect((!
data.
LIST->empty()), 0) ) {
1141 if( __builtin_expect((d->type ==
OksData::uid2_type && d->data.UID2.class_id->empty()), 0) )
continue;
1149OksData::read(
const ReadFileParams& read_params,
const OksRelationship * r)
1151 const OksClass * rel_class(r->p_class_type);
1152 OksString * class_id(0);
1153 const OksClass * c(0);
1154 OksXmlInputStream& fxs(read_params.s);
1160 size_t len = fxs.get_quoted();
1162 if( __builtin_expect((len > 0), 1) ) {
1163 if( __builtin_expect((!read_params.alias_table), 1) ) {
1164 if( __builtin_expect((rel_class != 0), 1) ) {
1165 c = rel_class->get_kernel()->find_class(fxs.get_xml_token().m_buf);
1168 if( __builtin_expect((c == 0), 0) ) {
1169 class_id =
new OksString(fxs.get_xml_token().m_buf, len);
1173 const char * class_name_str(fxs.get_xml_token().m_buf);
1175 if(class_name_str[0] ==
'@') {
1179 c = ( rel_class ? rel_class->get_kernel()->find_class(class_name_str) : 0 );
1182 read_params.alias_table->add_value(0, c);
1185 read_params.alias_table->add_value(
new OksString(class_name_str, len), 0);
1190 if(
const OksAliasTable::Value * value = read_params.alias_table->get(class_name_str)) {
1194 : rel_class->get_kernel()->find_class(*value->class_name)
1198 Oks::warning_msg(
"OksData::read(const ReadFileParams&, const OksRelationship*")
1199 <<
" Can't find alias for class \'" << class_name_str <<
"\'\n"
1200 " Possibly data file has been saved in old format\n";
1202 c = rel_class->get_kernel()->find_class(class_name_str);
1208 class_id =
new OksString(class_name_str, len);
1216 len = fxs.get_quoted();
1218 if( __builtin_expect((c == 0), 0) ) {
1220 Set(class_id,
new OksString(fxs.get_xml_token().m_buf, len));
1231 std::string& obj_id((
const_cast<ReadFileParams&
>(read_params)).tmp);
1232 obj_id.assign(fxs.get_xml_token().m_buf, len);
1233 OksObject * obj = c->get_object(obj_id);
1236 Set(c,
new OksString(obj_id));
1243 read_params.owner->OksObject::check_class_type(r, c);
1245 obj->add_RCR(read_params.owner, r);
1248 if(class_id)
delete class_id;
1249 throw FailedRead(
"relationship value", ex);
1251 catch (std::exception & ex) {
1252 if(class_id)
delete class_id;
1253 throw FailedRead(
"relationship value", ex.what());
1264OksData::read(
const OksRelationship * r,
const OksXmlRelValue& value)
1268 if (__builtin_expect((value.m_class ==
nullptr), 0))
1270 if (value.m_class_id)
1272 Set(value.m_class_id,
new OksString(value.m_value.buf(), value.m_value.len()));
1273 value.m_class_id =
nullptr;
1283 OksObject * obj = value.m_class->get_object(value.m_value.buf());
1287 Set(value.m_class,
new OksString(value.m_value.buf(), value.m_value.len()));
1293 value.m_file_params.owner->OksObject::check_class_type(r, value.m_class);
1295 obj->add_RCR(value.m_file_params.owner, r);
1299 if (value.m_class_id)
1300 delete value.m_class_id;
1301 throw FailedRead(
"relationship value", ex);
1303 catch (std::exception & ex)
1305 if (value.m_class_id)
1306 delete value.m_class_id;
1307 throw FailedRead(
"relationship value", ex.what());
1316OksData::read(
const OksRelationship *r,
const ReadFileParams& read_params)
1326 const char * tag_start = read_params.s.get_tag_start();
1334 OksXmlRelValue value(read_params);
1338 OksXmlAttribute attr(read_params.s);
1347 value.m_class = read_params.owner->uid.class_id->get_kernel()->find_class(attr.value());
1348 if( __builtin_expect((value.m_class ==
nullptr && attr.value_len() > 0), 0) ) {
1349 value.m_class_id =
new OksString(attr.value(), attr.value_len());
1353 value.m_value = read_params.s.get_value(attr.p_value_len);
1356 read_params.s.throw_unexpected_attribute(attr.name());
1359 if(value.is_empty() ==
false)
1364 if( __builtin_expect((d->type ==
OksData::uid2_type && d->data.UID2.class_id->empty()), 0) )
continue;
1371 throw FailedRead(
"multi-value relationship", e);
1373 catch (std::exception & e) {
1374 throw FailedRead(
"multi-value relationship", e.what());
1379 std::ostringstream s;
1380 s <<
"Unexpected tag \"" << tag_start <<
"\" (line " << read_params.s.get_line_no() <<
", char " << read_params.s.get_line_pos() <<
')';
1381 throw std::runtime_error(s.str().c_str());
1386 throw FailedRead(
"multi-value", e);
1388 catch (std::exception & e)
1390 throw FailedRead(
"multi-value", e.what());
1406 if(put_number) xmls.put_value((
unsigned long)
data.
LIST->size());
1415 (*i)->WriteTo(xmls, put_number);
1425 if(put_number) xmls.put_raw(
'0');
1451 std::ostream& s = xmls.get_stream();
1452 std::streamsize p = s.precision();
1453 s.precision(std::numeric_limits< float >::digits10);
1459 std::ostream& s = xmls.get_stream();
1460 std::streamsize p = s.precision();
1461 s.precision(std::numeric_limits< double >::digits10);
1467 xmls.put_value(
static_cast<int16_t
>(
data.
S8_INT));
1471 xmls.put_value(
static_cast<uint16_t
>(
data.
U8_INT));
1483 xmls.put_value((
short)(
data.
BOOL));
1487 xmls.put_quoted(boost::gregorian::to_iso_string(
date()).c_str());
1491 xmls.put_quoted(boost::posix_time::to_iso_string(
time()).c_str());
1507 <<
"Can't write \'" << (type ==
unknown_type ?
"unknown" :
"relationship") <<
"_type\'\n";
1538 std::ostream& s = xmls.get_stream();
1539 std::streamsize p = s.precision();
1540 s.precision(std::numeric_limits< float >::digits10);
1546 std::ostream& s = xmls.get_stream();
1547 std::streamsize p = s.precision();
1548 s.precision(std::numeric_limits< double >::digits10);
1554 xmls.put_value(
static_cast<int16_t
>(
data.
S8_INT));
1558 xmls.put_value(
static_cast<uint16_t
>(
data.
U8_INT));
1570 xmls.put_value((
short)(
data.
BOOL));
1574 xmls.put(boost::gregorian::to_iso_string(
date()).c_str());
1578 xmls.put(boost::posix_time::to_iso_string(
time()).c_str());
1590 throw std::runtime_error(
"internal error: call OksData::WriteTo() on list");
1597 <<
"Can't write \'" << (type ==
unknown_type ?
"unknown" :
"relationship") <<
"_type\'\n";
1609OksData::WriteTo(OksXmlOutputStream& xmls, OksKernel *k, OksAliasTable *alias_table,
bool ,
bool put_number)
const
1611 const char * fname =
"WriteTo(OksXmlOutputStream&, ...)";
1613 static std::string emptyName(
"");
1615 const std::string * class_name = 0;
1616 const std::string * object_id = 0;
1625 class_name = object_id = &emptyName;
1631 if(put_number) xmls.put_value((
unsigned long)
data.
LIST->size());
1641 (*i)->WriteTo(xmls, k, alias_table,
false, put_number);
1650 if(put_number) xmls.put_raw(
'0');
1661 class_name = &
data.
UID.class_id->get_name();
1662 object_id =
data.
UID.object_id;
1667 <<
"Can't write \'" << (type ==
unknown_type ?
"unknown" :
"attribute") <<
"_type\'\n";
1672 if(!class_name->empty()) {
1677 xmls.put_quoted(class_name->c_str());
1684 const OksAliasTable::Value *value = alias_table->get(
static_cast<const OksString *
>(class_name));
1688 xmls.put_quoted(value->class_name->c_str());
1692 alias_table->add_key(
static_cast<OksString *
>(
const_cast<std::string *
>(class_name)));
1694 std::string s(*class_name);
1696 xmls.put_quoted(s.c_str());
1702 xmls.put_quoted(
"");
1706 xmls.put_quoted(object_id->c_str());
1713 to->Set(
new List());
1722 to->data.LIST->push_back(item);
1732 else if(dd->type ==
OksData::uid_type) item->Set(dd->data.UID.class_id, *dd->data.UID.object_id);
1733 else if(dd->type ==
OksData::uid2_type) item->Set(*dd->data.UID2.class_id, *dd->data.UID2.object_id);
1735 to->data.LIST->push_back(item);
1746 else if(from->type ==
OksData::uid_type) to->Set(from->data.UID.class_id, *from->data.UID.object_id);
1747 else if(from->type ==
OksData::uid2_type) to->Set(*from->data.UID2.class_id, *from->data.UID2.object_id);
1755 if(a->get_is_multi_values()) {
1756 to->Set(
new List());
1761 std::string cvts =
str();
1762 item->ReadFrom(cvts.c_str(), a->get_data_type(), a);
1764 to->data.LIST->push_back(item);
1773 std::string cvts = dd->str();
1774 item->ReadFrom(cvts.c_str(), a->get_data_type(), a);
1776 to->data.LIST->push_back(item);
1785 if(from) cvts = from->str();
1786 to->ReadFrom(cvts.c_str(), a->get_data_type(), a);
1792list2str(
const OksData::List * l,
const OksKernel * k,
int base)
1794 std::ostringstream s;
1799 bool is_first =
true;
1801 for(OksData::List::const_iterator i = l->begin(); i != l->end(); ++i) {
1802 std::string s2 = (k ? (*i)->str(k) : (*i)->str(base));
1805 if(is_first ==
false) { s <<
", "; }
1806 else { is_first =
false; }
1825 return list2str(
data.
LIST, kernel, 0);
1828 std::ostringstream s;
1836 s <<
"#[" << *
data.
UID.object_id <<
'@' <<
data.
UID.class_id->get_name() <<
']';
1846 std::cerr <<
"ERROR [OksData::str(const OksKernel *)]: wrong use for such data: " << *
this << std::endl;
1863 else if(type ==
date_type) {
return boost::gregorian::to_simple_string(
date()); }
1864 else if(type ==
time_type) {
return boost::posix_time::to_simple_string(
time()); }
1868 std::ostringstream s;
1871 s.setf((base == 10 ? std::ios::dec : base == 16 ? std::ios::hex : std::ios::oct), std::ios::basefield );
1872 s.setf(std::ios::showbase);
1909 s.precision(std::numeric_limits< float >::digits10);
1914 s.precision(std::numeric_limits< double >::digits10);
1919 std::cerr <<
"ERROR [OksData::str(int)]: wrong use for such data: " << *
this << std::endl;
1936 if(o->GetClass()->get_kernel()->get_silence_mode() !=
true) {
1937 std::cerr << msg <<
": value of \"" << r->get_name() <<
"\" relationship in object " << o <<
" must be non-null\n";
1942 if(o->GetClass()->get_kernel()->get_silence_mode() !=
true) {
1943 std::cerr << msg <<
": \"" << r->get_name() <<
"\" relationship in object " << o <<
" must contain at least one object\n";
1966 boost::posix_time::ptime
str2time(
const char * value,
size_t len,
const char * file_name)
1968 if(len == 15 && value[8] ==
'T') {
1970 return boost::posix_time::from_iso_string(value);
1972 catch (std::exception& ex) {
1974 throw AttributeReadError(value,
"time", ex.what());
1980 std::ostringstream text;
1981 text << std::setfill(
'0')
1982 << std::setw(4) << t.year()
1983 << std::setw(2) << (t.month() + 1)
1984 << std::setw(2) << t.day()
1986 << std::setw(2) << t.hour()
1987 << std::setw(2) << t.min()
1988 << std::setw(2) << t.sec();
1989 TLOG_DEBUG( 1 ) <<
"parse OKS time: " << t <<
" => " << text.str() ;
1994 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";
1996 return boost::posix_time::from_iso_string(text.str());
2000 throw AttributeReadError(value,
"time", ex);
2002 catch (std::exception& ex) {
2004 throw AttributeReadError(value,
"time", ex.what());
2009 boost::gregorian::date
str2date(
const char * value,
size_t len)
2011 if(len == 8 && value[2] !=
'/' && value[3] !=
'/') {
2013 return boost::gregorian::from_undelimited_string(value);
2015 catch (std::exception& ex) {
2016 throw AttributeReadError(value,
"date", ex.what());
2022 std::ostringstream text;
2023 text << std::setfill(
'0')
2024 << std::setw(4) << t.year()
2025 << std::setw(2) << (t.month() + 1)
2026 << std::setw(2) << t.day();
2027 TLOG_DEBUG( 1 ) <<
"parse OKS date: " << t <<
" => " << text.str() ;
2029 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";
2031 return boost::gregorian::from_undelimited_string(text.str());
2034 throw AttributeReadError(value,
"date", ex);
2036 catch (std::exception& ex) {
2037 throw AttributeReadError(value,
"date", ex.what());