73 #include <xercesc/util/XMLUri.hpp>
83 #define X(str) XString(str).unicode_str()
84 #define S(str) str.c_str()
86 using namespace xercesc;
94 <<
" hddm-cpp [-v | -o <filename>] {HDDM file}\n\n"
96 <<
" -v validate only\n"
97 <<
" -o <filename> write to <filename>.hpp, <filename>.cpp"
136 void checkConsistency(DOMElement* el, DOMElement* elref);
137 void writeClassdef(DOMElement* el);
138 void writeClassimp(DOMElement* el);
139 void constructDocument(DOMElement* el);
140 void constructGroup(DOMElement* el);
141 void constructIOstreams(DOMElement* el);
142 void constructMethods(DOMElement* el);
143 void constructStreamers(DOMElement* el);
144 void writeStreamers(DOMElement* el);
147 std::vector<DOMElement*> tagList;
157 int main(
int argC,
char* argV[])
161 XMLPlatformUtils::Initialize();
163 catch (
const XMLException* toCatch)
165 XtString msg(toCatch->getMessage());
167 <<
"hddm-cpp: Error during initialization! :\n"
177 else if ((argC == 2) && (strcmp(argV[1],
"-?") == 0))
185 bool verifyOnly =
false;
187 for (argInd = 1; argInd < argC; argInd++)
189 if (argV[argInd][0] !=
'-')
193 if (strcmp(argV[argInd],
"-v") == 0)
197 else if (strcmp(argV[argInd],
"-o") == 0)
199 hFilename =
XtString(argV[++argInd]);
204 <<
"Unknown option \'" << argV[argInd]
205 <<
"\', ignoring it\n" << std::endl;
209 if (argInd != argC - 1)
216 #if defined OLD_STYLE_XERCES_PARSER
224 <<
"hddm-cpp : Error parsing HDDM document, "
225 <<
"cannot continue" << std::endl;
229 DOMElement* rootEl = document->getDocumentElement();
230 XtString rootS(rootEl->getTagName());
234 <<
"hddm-cpp error: root element of input document is "
235 <<
"\"" << rootS <<
"\", expected \"HDDM\""
240 XtString classS(rootEl->getAttribute(
X(
"class")));
248 else if (hFilename.size())
250 hname = hFilename +
".hpp";
254 hname =
"hddm_" + classPrefix +
".hpp";
258 builder.
hFile.open(hname.c_str());
259 if (! builder.
hFile.is_open())
262 <<
"hddm-cpp error: unable to open output file "
263 << hname << std::endl;
272 else if (hFilename.size())
274 cname = hFilename +
".cpp";
278 cname =
"hddm_" + classPrefix +
".cpp";
281 builder.
cFile.open(cname.c_str());
282 if (! builder.
cFile.is_open())
285 <<
"hddm-cpp error: unable to open output file "
286 << cname << std::endl;
292 " * hddm_" << classPrefix <<
".hpp - DO NOT EDIT THIS FILE\n"
294 " * This file was generated automatically by hddm-cpp from the file\n"
295 <<
" * " << xmlFile << std::endl <<
297 " * This header file defines the c++ classes that hold the data\n"
298 " * described in the data model (from " << xmlFile <<
"). \n"
300 " * The hddm data model tool set was written by\n"
301 " * Richard Jones, University of Connecticut.\n"
303 " * For more information see the following web site\n"
305 " * http://zeus.phys.uconn.edu/halld/datamodel/doc\n"
309 "#ifndef SAW_" << classPrefix <<
"_HDDM\n"
310 "#define SAW_" << classPrefix <<
"_HDDM\n"
314 "#include <vector>\n"
315 "#include <string>\n"
316 "#include <atomic>\n"
317 "#include <sstream>\n"
318 "#include <stdexcept>\n"
319 "#include <streambuf>\n"
320 "#include <xstream/z.h>\n"
321 "#include <xstream/bz.h>\n"
322 "#include <xstream/xdr.h>\n"
323 "#include <xstream/digest.h>\n"
324 "#include <particleType.h>\n"
325 "#include <pthread.h>\n"
327 "#define MY_SETUP thread_private_data *my_private = lookup_private_data();\n"
328 "#define MY(VAR) my_private->m_ ## VAR\n"
330 "namespace hddm_" << classPrefix <<
" {\n"
332 "const int k_default_status = 0x0;\n"
333 "const int k_bits_compression = 0xf0;\n"
334 "const int k_no_compression = 0x00;\n"
335 "const int k_z_compression = 0x10;\n"
336 "const int k_bz2_compression = 0x20;\n"
337 "const int k_bits_integrity = 0x0f;\n"
338 "const int k_no_integrity = 0x00;\n"
339 "const int k_crc32_integrity = 0x01;\n"
340 "const int k_bits_randomaccess = 0xf00;\n"
341 "const int k_can_reposition = 0x100;\n"
352 " k_hddm_Particle_t\n"
359 "class streamable {\n"
361 " virtual ~streamable() {}\n"
362 " virtual void streamer(istream &istr) {}\n"
363 " virtual void streamer(ostream &ostr) {}\n"
366 "class streamposition {\n"
368 " uint64_t block_start;\n"
369 " uint32_t block_offset;\n"
370 " uint32_t block_status;\n"
371 " streamposition();\n"
372 " streamposition(uint64_t start, uint32_t offset, uint32_t status);\n"
373 " bool operator==(const streamposition src) const {\n"
374 " return (block_start == src.block_start &&\n"
375 " block_offset == src.block_offset &&\n"
376 " block_status == src.block_status);\n"
378 " bool operator!=(const streamposition src) const {\n"
379 " return !(*this == src);\n"
381 " bool operator>(const streamposition src) const {\n"
382 " return (block_start > src.block_start ||\n"
383 " (block_start == src.block_start &&\n"
384 " block_offset > src.block_offset));\n"
386 " bool operator>=(const streamposition src) const {\n"
387 " return (*this > src || *this == src);\n"
389 " bool operator<(const streamposition src) const {\n"
390 " return !(*this >= src);\n"
392 " bool operator<=(const streamposition src) const {\n"
393 " return !(*this > src);\n"
399 " static thread_local int ID;\n"
400 " static int getID() {\n"
401 " // protected access to the ID tls data member\n"
403 " if (ID >= max_threads) {\n"
404 " throw std::runtime_error(\"hddm_"
405 << classPrefix <<
"::threads::getID - \"\n"
406 " \"thread count exceeds max_threads\");\n"
408 " ID = ++next_unique_ID;\n"
412 " static const int max_threads = 999;\n"
414 " static std::atomic<int> next_unique_ID;\n"
417 "class istreambuffer : public std::streambuf {\n"
419 " istreambuffer(char* buffer, std::streamsize bufferLength) {\n"
420 " setg(buffer, buffer, buffer + bufferLength);\n"
423 " std::streampos tellg() {\n"
424 " return gptr() - eback();\n"
427 " void seekg(std::streampos pos) {\n"
433 " return egptr() - gptr();\n"
437 " char *gbegin = eback();\n"
438 " char *gend = egptr();\n"
439 " setg(gbegin, gbegin, gend);\n"
442 " char *getbuf() {\n"
447 "class ostreambuffer : public std::streambuf {\n"
449 " ostreambuffer(char* buffer, std::streamsize bufferLength) {\n"
450 " setp(buffer, buffer + bufferLength);\n"
453 " std::streampos tellp() {\n"
454 " return pptr() - pbase();\n"
457 " void seekp(std::streampos pos) {\n"
463 " return pptr() - pbase();\n"
467 " char *pbegin = pbase();\n"
468 " char *pend = epptr();\n"
469 " setp(pbegin, pend);\n"
472 " char *getbuf() {\n"
479 " ostream(std::ostream &src);\n"
481 " ostream &operator<<(HDDM &record);\n"
482 " int getCompression() const;\n"
483 " void setCompression(int flags);\n"
484 " int getIntegrityChecks() const;\n"
485 " void setIntegrityChecks(int flags);\n"
486 " streamposition getPosition();\n"
487 " int getBytesWritten() const;\n"
488 " int getRecordsWritten() const;\n"
490 " xstream::xdr::ostream *getXDRostream() {\n"
491 " return my_thread_private[threads::ID]->m_xstr;\n"
493 " ostream &operator<<(streamable &object);\n"
495 " void configure_streambufs();\n"
496 " void update_streambufs();\n"
497 " void lock_streambufs();\n"
498 " void unlock_streambufs();\n"
499 " std::ostream &m_ostr;\n"
500 " std::atomic<int> m_status_bits;\n"
501 " pthread_mutex_t m_streambuf_mutex;\n"
503 " typedef struct {\n"
504 " xstream::xdr::ostream *m_xstr;\n"
505 " std::ostream *m_ostr;\n"
506 " ostreambuffer *m_sbuf;\n"
507 " std::streambuf *m_xcmp;\n"
508 " char *m_event_buffer;\n"
509 " int m_event_buffer_size;\n"
510 " std::streampos m_last_start;\n"
511 " std::streamoff m_last_offset;\n"
512 " int m_status_bits;\n"
513 " int m_mutex_lock;\n"
514 " int m_bytes_written;\n"
515 " int m_records_written;\n"
516 " } thread_private_data;\n"
518 " thread_private_data *my_thread_private[threads::max_threads];\n"
519 " thread_private_data *lookup_private_data();\n"
520 " void init_private_data();\n"
525 " codon(): m_order(0) {}\n"
527 " std::string m_tagname;\n"
528 " std::vector<codon> m_sequence;\n"
529 " std::deque<streamable*> m_target;\n"
532 "typedef std::vector<codon> chromosome;\n"
536 " istream(std::istream &src);\n"
538 " istream &operator>>(HDDM &record);\n"
539 " void skip(int count);\n"
540 " int getCompression() const;\n"
541 " int getIntegrityChecks() const;\n"
542 " streamposition getPosition();\n"
543 " void setPosition(const streamposition &pos);\n"
544 " int getBytesRead() const;\n"
545 " int getRecordsRead() const;\n"
547 " bool operator!();\n"
548 " operator void*();\n"
550 " void reset_sequencer();\n"
551 " void sequencer(streamable &object);\n"
552 " istream &operator>>(streamable &object);\n"
553 " xstream::xdr::istream *getXDRistream() {\n"
554 " return my_thread_private[threads::ID]->m_xstr;\n"
558 " std::string m_documentString;\n"
559 " chromosome synthesize(const std::string &src, int p_src,\n"
560 " const std::string &ref, int p_ref);\n"
561 " int getTag(const std::string &src, int p_src, std::string &tag, int &level);\n"
562 " int getEndTag(const std::string &src, int p_src, const std::string &tag);\n"
563 " void collide(const std::string &itag, const std::string &rtag);\n"
564 " void configure_streambufs();\n"
565 " void update_streambufs();\n"
566 " void lock_streambufs();\n"
567 " void unlock_streambufs();\n"
568 " std::istream &m_istr;\n"
569 " std::atomic<int> m_status_bits;\n"
570 " pthread_mutex_t m_streambuf_mutex;\n"
571 " int m_leftovers[100];\n"
573 " typedef struct {\n"
576 " int m_sequencing;\n"
577 " xstream::xdr::istream *m_xstr;\n"
578 " std::istream *m_istr;\n"
579 " istreambuffer *m_sbuf;\n"
580 " std::streambuf *m_xcmp;\n"
581 " int m_events_to_skip;\n"
582 " char *m_event_buffer;\n"
583 " int m_event_buffer_size;\n"
584 " int m_event_size;\n"
585 " std::streampos m_last_start;\n"
586 " std::streamoff m_last_offset;\n"
587 " std::streamoff m_next_start;\n"
588 " int m_status_bits;\n"
589 " int m_mutex_lock;\n"
590 " int m_bytes_read;\n"
591 " int m_records_read;\n"
593 " } thread_private_data;\n"
595 " thread_private_data *my_thread_private[threads::max_threads];\n"
596 " thread_private_data *lookup_private_data();\n"
597 " void init_private_data();\n"
600 "template <class T> class HDDM_ElementList;\n"
602 "class HDDM_Element: public streamable {\n"
604 " ~HDDM_Element() {}\n"
605 " virtual const void *getAttribute(const std::string &name,\n"
606 " hddm_type *atype=0) const {\n"
609 " virtual std::string toString(int indent=0) {\n"
610 " return \"bad apple\";\n"
612 " virtual std::string toXML(int indent=0) {\n"
613 " return \"<!--bad apple-->\";\n"
615 " friend class HDDM_ElementList<HDDM_Element>;\n"
617 " HDDM_Element() : m_parent(0), m_host(0) {}\n"
618 " HDDM_Element(HDDM_Element *parent)\n"
619 " : m_parent(parent),\n"
620 " m_host(parent->m_host)\n"
622 " HDDM_Element(HDDM_Element &src)\n"
623 " : m_parent(src.m_parent),\n"
624 " m_host(src.m_host)\n"
626 " HDDM_Element *m_parent;\n"
630 "template <class T>\n"
631 "class HDDM_ElementList: public streamable {\n"
633 " HDDM_ElementList(typename std::list<T*> *plist,\n"
634 " typename std::list<T*>::iterator begin,\n"
635 " typename std::list<T*>::iterator end,\n"
636 " HDDM_Element *parent=0)\n"
637 " : m_host_plist(plist),\n"
638 " m_first_iter(begin),\n"
639 " m_last_iter(end),\n"
640 " m_parent(parent)\n"
642 " for (m_size = 0; begin != end; ++m_size, ++begin) {}\n"
648 " HDDM_ElementList(const HDDM_ElementList<T> &src)\n"
649 " : m_host_plist(src.m_host_plist),\n"
650 " m_first_iter(src.m_first_iter),\n"
651 " m_last_iter(src.m_last_iter),\n"
653 " m_size(src.m_size)\n"
656 " bool empty() const { return (m_size == 0); }\n"
657 " int size() const { return m_size; }\n"
658 " T &front() const { return *m_first_iter; }\n"
659 " T &back() const { return *m_last_iter; }\n"
660 " T &operator()() { return *m_first_iter; }\n"
661 " T &operator()(int index) {\n"
662 " if (index == 0) {\n"
663 " return *m_first_iter;\n"
665 " else if (index == -1) {\n"
666 " return *m_last_iter;\n"
668 " else if (index > 0) {\n"
669 " return *(m_first_iter + index);\n"
672 " return *(m_last_iter + (++index));\n"
676 " class iterator: public std::list<T*>::iterator {\n"
679 " iterator(typename std::list<T*>::iterator src)\n"
680 " : std::list<T*>::iterator(src) {}\n"
682 " T *operator->() const { \n"
683 " return *(typename std::list<T*>::iterator)(*this);\n"
686 " T &operator*() const {\n"
687 " return **(typename std::list<T*>::iterator)(*this);\n"
690 " iterator operator+=(int offset) {\n"
691 " if (offset > 0) {\n"
692 " for (int i=0; i<offset; ++i, ++(*this)) {}\n"
694 " else if (offset < 0) {\n"
695 " for (int i=0; i>offset; --i, --(*this)) {}\n"
700 " iterator operator-=(int offset) {\n"
701 " if (offset > 0) {\n"
702 " for (int i=0; i<offset; ++i, --(*this)) {}\n"
704 " else if (offset < 0) {\n"
705 " for (int i=0; i>offset; --i, ++(*this)) {}\n"
710 " iterator operator+(int offset) const {\n"
711 " iterator iter(*this);\n"
712 " return iter += offset;\n"
715 " iterator operator-(int offset) const {\n"
716 " iterator iter(*this);\n"
717 " return iter -= offset;\n"
720 " int operator-(iterator iter) const {\n"
721 " if (*this == iter) {\n"
724 " iterator iter2(iter);\n"
725 " for (int n=1; n < m_size; ++n) {\n"
726 " if (++iter == *this) {\n"
729 " else if (--iter2 == *this) {\n"
737 " class const_iterator: public std::list<T*>::const_iterator {\n"
739 " const_iterator() {}\n"
740 " const_iterator(const typename std::list<T*>::const_iterator src)\n"
741 " : std::list<T*>::const_iterator(src) {}\n"
743 " const_iterator(const typename std::list<T*>::iterator src)\n"
744 " : std::list<T*>::const_iterator(src) {}\n"
746 " const T *operator->() const { \n"
747 " return *(typename std::list<T*>::const_iterator)(*this);\n"
750 " const T &operator*() const { \n"
751 " return **(typename std::list<T*>::const_iterator)(*this);\n"
754 " const const_iterator operator+=(int offset) {\n"
755 " if (offset > 0) {\n"
756 " for (int i=0; i<offset; ++i, ++(*this)) {}\n"
758 " else if (offset < 0) {\n"
759 " for (int i=0; i>offset; --i, --(*this)) {}\n"
764 " const const_iterator operator-=(int offset) {\n"
765 " if (offset > 0) {\n"
766 " for (int i=0; i<offset; ++i, --(*this)) {}\n"
768 " else if (offset > 0) {\n"
769 " for (int i=0; i>offset; --i, ++(*this)) {}\n"
774 " const const_iterator operator+(int offset) const {\n"
775 " const_iterator iter(*this);\n"
776 " return iter += offset;\n"
779 " const const_iterator operator-(int offset) const {\n"
780 " const_iterator iter(*this);\n"
781 " return iter -= offset;\n"
784 " int operator-(const_iterator iter) const {\n"
785 " if (*this == iter) {\n"
788 " const_iterator iter2(iter);\n"
789 " for (int n=1; n < m_size; ++n) {\n"
790 " if (++iter == *this) {\n"
793 " else if (--iter2 == *this) {\n"
801 " iterator begin() const { return m_first_iter; }\n"
802 " iterator end() const { return (m_size)? m_last_iter + 1 : m_last_iter; }\n"
803 " void clear() { del(); }\n"
805 " HDDM_ElementList add(int count=1, int start=-1) {\n"
806 " if (m_parent == 0) {\n"
807 " throw std::runtime_error(\"HDDM_ElementList error - \"\n"
808 " \"attempt to add to immutable list\");\n"
810 " iterator it = insert(start, count);\n"
811 " typename std::list<T*>::iterator iter(it);\n"
812 " for (int n=0; n<count; ++n, ++iter) {\n"
813 " *iter = new T(m_parent);\n"
815 " return HDDM_ElementList(m_host_plist, it, it+count, m_parent);\n"
818 " void del(int count=-1, int start=0) {\n"
819 " if (m_parent == 0) {\n"
820 " throw std::runtime_error(\"HDDM_ElementList error - \"\n"
821 " \"attempt to delete from immutable list\");\n"
823 " iterator iter_begin(begin());\n"
824 " iterator iter_end(end());\n"
825 " if (start < 0) {\n"
826 " if (count >= 0) {\n"
827 " iter_begin = iter_end - count;\n"
831 " iter_begin += start;\n"
832 " if (count >= 0) {\n"
833 " iter_end = iter_begin + count;\n"
836 " typename std::list<T*>::iterator iter;\n"
837 " for (iter = iter_begin; iter != iter_end; ++iter) {\n"
840 " erase(start, count);\n"
843 " HDDM_ElementList slice(int first=0, int last=-1) {\n"
844 " int n1 = (first < 0)? first + m_size : first;\n"
845 " int n2 = (last < 0)? last + m_size + 1 : last + 1;\n"
846 " int count = n2 - n1;\n"
847 " iterator iter_begin;\n"
849 " iter_begin = begin() + first;\n"
850 " else if (first < 0)\n"
851 " iter_begin = end() + first;\n"
852 " iterator iter_end(iter_begin + count);\n"
853 " return HDDM_ElementList(m_host_plist, iter_begin, iter_end);\n"
856 " void streamer(istream &istr) {\n"
859 " *istr.getXDRistream() >> size;\n"
861 " iterator iter = add(size).begin();\n"
862 " for (int n=0; n < size; ++n, ++iter) {\n"
863 " istr.sequencer(*iter);\n"
866 " istr.reset_sequencer();\n"
869 " void streamer(ostream &ostr) {\n"
871 " *ostr.getXDRostream() << m_size;\n"
872 " for (iterator iter = begin(); iter != end(); ++iter) {\n"
873 " iter->streamer(ostr);\n"
877 " std::string toString(int indent=0) {\n"
878 " std::string result;\n"
880 " for (iterator iter = begin(); iter != end(); ++iter) {\n"
881 " result += iter->toString(indent);\n"
886 " std::string toXML(int indent=0) {\n"
887 " std::string result;\n"
889 " for (iterator iter = begin(); iter != end(); ++iter) {\n"
890 " result += iter->toXML(indent);\n"
897 " HDDM_ElementList() {}\n"
899 " iterator insert(int start, int count) {\n"
900 " if (m_size == 0) {\n"
901 " if (count > 0) {\n"
902 " if (m_first_iter == m_host_plist->begin()) {\n"
903 " m_host_plist->insert(m_first_iter,count,(T*)0);\n"
904 " m_first_iter = m_host_plist->begin();\n"
907 " m_host_plist->insert(m_first_iter--,count,(T*)0);\n"
913 " return m_first_iter;\n"
915 " else if (start == 0) {\n"
916 " if (count > 0) {\n"
917 " if (m_first_iter == m_host_plist->begin()) {\n"
918 " m_host_plist->insert(m_first_iter,count,(T*)0);\n"
919 " m_first_iter = m_host_plist->begin();\n"
922 " m_host_plist->insert(m_first_iter--,count,(T*)0);\n"
925 " m_size += count;\n"
927 " return m_first_iter;\n"
929 " else if (start == -1) {\n"
930 " if (count > 0) {\n"
931 " iterator pos(m_last_iter);\n"
932 " m_host_plist->insert(++m_last_iter,count,(T*)0);\n"
934 " m_size += count;\n"
937 " return m_last_iter;\n"
939 " else if (start > 0) {\n"
940 " if (count > 0) {\n"
941 " iterator pos(m_first_iter);\n"
942 " iterator pos2(pos += start-1);\n"
943 " m_host_plist->insert(++pos,count,(T*)0);\n"
944 " if (m_last_iter == pos2) {\n"
945 " m_last_iter = --pos;\n"
947 " m_size += count;\n"
950 " return m_first_iter + start;\n"
953 " if (count > 0) {\n"
954 " iterator pos(m_last_iter);\n"
955 " iterator pos2(pos += start+1);\n"
956 " m_host_plist->insert(++pos,count,(T*)0);\n"
957 " m_size += count;\n"
960 " return m_last_iter + (start+1);\n"
964 " iterator erase(int start, int count) {\n"
965 " if (m_size == 0) {\n"
966 " return m_first_iter+start;\n"
968 " else if ((count >= m_size || count == -1) &&\n"
969 " (start == 0 || start <= -m_size)) {\n"
970 " m_host_plist->erase(m_first_iter,++m_last_iter);\n"
971 " m_first_iter = m_last_iter;\n"
973 " return m_first_iter;\n"
975 " else if (start > 0 && start <= m_size) {\n"
977 " count = (count < 0)? m_size-start : count;\n"
978 " iterator pos(m_first_iter + start);\n"
979 " iterator pos2(pos + count);\n"
980 " m_host_plist->erase(pos,pos2);\n"
981 " m_size -= count;\n"
985 " else if (start < 0 && start >= -m_size) {\n"
987 " count = (count < 0)? -start : count;\n"
988 " iterator pos(m_last_iter + (start+1));\n"
989 " iterator pos2(pos + count);\n"
990 " m_host_plist->erase(pos,pos2);\n"
991 " if (m_size -= count) {\n"
995 " m_first_iter = m_last_iter;\n"
999 " return m_last_iter+1;\n"
1003 " std::list<T*> *m_host_plist;\n"
1004 " iterator m_first_iter;\n"
1005 " iterator m_last_iter;\n"
1006 " HDDM_Element *m_parent;\n"
1010 "template <class T>\n"
1011 "class HDDM_ElementLink: public HDDM_ElementList<T> {\n"
1013 " HDDM_ElementLink(typename std::list<T*> *plist,\n"
1014 " typename std::list<T*>::iterator begin,\n"
1015 " typename std::list<T*>::iterator end,\n"
1016 " HDDM_Element *parent)\n"
1017 " : HDDM_ElementList<T>(plist,begin,end,parent)\n"
1019 " HDDM_ElementLink(const HDDM_ElementList<T> &src)\n"
1020 " : HDDM_ElementList<T>(src)\n"
1023 " void streamer(istream &istr) {\n"
1024 " HDDM_ElementList<T>::clear();\n"
1025 " HDDM_ElementList<T>::add().begin()->streamer(istr);\n"
1028 " void streamer(ostream &ostr) {\n"
1029 " if (HDDM_ElementList<T>::m_size) {\n"
1030 " HDDM_ElementList<T>::begin()->streamer(ostr);\n"
1035 " HDDM_ElementLink() {}\n"
1042 " * hddm_" << classPrefix <<
".cpp - DO NOT EDIT THIS FILE\n"
1044 " * This file was generated automatically by hddm-cpp from the file\n"
1045 <<
" * " << xmlFile << std::endl <<
1047 " * This c++ source implements the methods for the classes \n"
1048 " * described in the data model (from " << xmlFile <<
"). \n"
1050 " * The hddm data model tool set was written by\n"
1051 " * Richard Jones, University of Connecticut.\n"
1053 " * For more information see the following web site\n"
1055 " * http://zeus.phys.uconn.edu/halld/datamodel/doc\n"
1058 "#include <sstream>\n"
1059 "#include \"hddm_" << classPrefix <<
".hpp\"\n"
1061 "#ifndef _FILE_OFFSET_BITS\n"
1062 "# define _FILE_OFFSET_BITS 64\n"
1065 "using namespace hddm_" << classPrefix <<
";\n"
1067 "std::atomic<int> threads::next_unique_ID(0);\n"
1068 "thread_local int threads::ID(0);\n"
1070 "static int tags_match(const std::string &a, const std::string &b)\n"
1076 " int len = a.length();\n"
1079 " for (; a[ia] == b[ib]; ++ia, ++ib, --len) {}\n"
1080 " for (; a[ia] == ' '; ++ia, --len) {}\n"
1081 " for (; a[ia] == '/'; ++ia, --len) {}\n"
1082 " for (; b[ib] == ' '; ++ib) {}\n"
1083 " for (; b[ib] == '/'; ++ib) {}\n"
1084 " return (a.substr(ia) == b.substr(ib));\n"
1096 "inline std::string HDDM::DocumentString() {\n"
1097 " return std::string(\n"
1105 "#endif /* SAW_" << classPrefix <<
"_HDDM */\n"
1110 "streamposition::streamposition()\n"
1111 " : block_start(), block_offset(), block_status() {}\n"
1113 "streamposition::streamposition(uint64_t start, uint32_t offset, uint32_t status)\n"
1114 " : block_start(start), block_offset(offset), block_status(status) {}\n"
1116 "istream::istream(std::istream &src)\n"
1118 " m_status_bits(0)\n"
1121 " src.getline(hdr,7);\n"
1122 " m_documentString = hdr;\n"
1123 " if (m_documentString != \"<HDDM \") {\n"
1124 " throw std::runtime_error(\"hddm_" + classPrefix +
1125 "::istream::istream error - invalid hddm header\");\n"
1128 " std::string line;\n"
1129 " while (std::getline(src,line).good()) {\n"
1130 " m_documentString += line + \"\\n\";\n"
1131 " if (line == \"</HDDM>\") {\n"
1135 " if (src.bad()) {\n"
1136 " throw std::runtime_error(\"hddm_" + classPrefix +
1137 "::istream::istream error - invalid hddm header\");\n"
1139 " pthread_mutex_init(&m_streambuf_mutex,0);\n"
1140 " for (int i=0; i<threads::max_threads; ++i) {\n"
1141 " my_thread_private[i] = 0;\n"
1143 " m_leftovers[0] = 0;\n"
1144 " init_private_data();\n"
1147 "istream::~istream() {\n"
1148 " pthread_mutex_destroy(&m_streambuf_mutex);\n"
1149 " for (int i=0; i<threads::max_threads; ++i) {\n"
1150 " thread_private_data *my_private = my_thread_private[i];\n"
1151 " if (my_private != 0) {\n"
1153 " delete MY(istr);\n"
1155 " delete MY(xcmp);\n"
1157 " delete MY(xstr);\n"
1159 " delete MY(sbuf);\n"
1160 " delete [] MY(event_buffer);\n"
1161 " delete my_private;\n"
1166 "void istream::init_private_data() {\n"
1167 " int threadID = threads::getID();\n"
1168 " if (my_thread_private[threadID] == 0) {\n"
1169 " my_thread_private[threadID] = new thread_private_data;\n"
1172 " MY(genome).m_tagname = \"HDDM\";\n"
1173 " MY(genome).m_sequence = synthesize(m_documentString,0,HDDM::DocumentString(),0);\n"
1174 " MY(event_buffer) = new char[MY(event_buffer_size) = 100000];\n"
1175 " MY(sbuf) = new istreambuffer(MY(event_buffer),MY(event_buffer_size));\n"
1176 " MY(xstr) = new xstream::xdr::istream(MY(sbuf));\n"
1177 " MY(istr) = new std::istream(m_istr.rdbuf());\n"
1179 " MY(event_size) = 0;\n"
1180 " MY(last_start) = 0;\n"
1181 " MY(last_offset) = 0;\n"
1182 " MY(next_start) = 0;\n"
1183 " MY(events_to_skip) = 0;\n"
1184 " MY(status_bits) = 0;\n"
1185 " MY(mutex_lock) = 0;\n"
1186 " MY(bytes_read) = 0;\n"
1187 " MY(records_read) = 0;\n"
1188 " MY(sequencing) = 0;\n"
1189 " MY(hit_eof) = 0;\n"
1192 "streamposition istream::getPosition() {\n"
1194 " streamposition pos;\n"
1195 " pos.block_start = MY(last_start);\n"
1196 " pos.block_offset = MY(last_offset);\n"
1197 " pos.block_status = MY(status_bits);\n"
1201 "void istream::setPosition(const streamposition &pos) {\n"
1203 " m_status_bits = pos.block_status;\n"
1204 " lock_streambufs();\n"
1205 " update_streambufs();\n"
1206 " unlock_streambufs();\n"
1207 " if (MY(status_bits) & (k_bz2_compression | k_z_compression)) {\n"
1208 " if (((int)m_status_bits & k_bits_compression) != 0 &&\n"
1209 " ((int)m_status_bits & k_can_reposition) == 0)\n"
1211 " throw std::runtime_error(\"hddm_"
1212 << classPrefix <<
"::istream::setPosition error - \"\n"
1213 " \"old-format hddm input file does not support repositioning.\");\n"
1215 " else if (MY(xcmp) == 0) {\n"
1216 " throw std::runtime_error(\"hddm_"
1217 << classPrefix <<
"::istream::setPosition error - \"\n"
1218 " \"compressed stream encountered but no decompressor configured.\");\n"
1220 " if (MY(status_bits) & k_z_compression) {\n"
1221 " ((xstream::z::istreambuf*)MY(xcmp))->\n"
1222 " set_new_position(pos.block_start, pos.block_offset);\n"
1224 " else if (MY(status_bits) & k_bz2_compression) {\n"
1225 " ((xstream::bz::istreambuf*)MY(xcmp))->\n"
1226 " set_new_position(pos.block_start, pos.block_offset);\n"
1230 " MY(next_start) = pos.block_start;\n"
1234 "void istream::update_streambufs() {\n"
1236 " if ((int)m_status_bits != MY(status_bits)) {\n"
1237 " configure_streambufs();\n"
1241 "void istream::configure_streambufs() {\n"
1243 " int oldcmp = MY(status_bits) & k_bits_compression;\n"
1244 " int newcmp = (int)m_status_bits & k_bits_compression;\n"
1245 " if (oldcmp != newcmp) {\n"
1246 " if (oldcmp != k_no_compression) {\n"
1247 " MY(istr)->rdbuf(m_istr.rdbuf());\n"
1248 " delete MY(xcmp);\n"
1251 " if (newcmp == k_z_compression) {\n"
1252 " //std::cerr << \"input switched on z compression\" << std::endl;\n"
1253 " MY(xcmp) = new xstream::z::istreambuf(m_istr.rdbuf(), m_leftovers,\n"
1254 " sizeof(m_leftovers));\n"
1255 " MY(istr)->rdbuf(MY(xcmp));\n"
1257 " else if (newcmp == k_bz2_compression) {\n"
1258 " //std::cerr << \"input switched on bz2 compression\" << std::endl;\n"
1259 " MY(xcmp) = new xstream::bz::istreambuf(m_istr.rdbuf(), m_leftovers,\n"
1260 " sizeof(m_leftovers));\n"
1261 " MY(istr)->rdbuf(MY(xcmp));\n"
1263 " else if (newcmp != k_no_compression) {\n"
1264 " throw std::runtime_error(\"hddm_"
1265 << classPrefix <<
"::istream::configure_streambufs error - \"\n"
1266 " \"unrecognized compression flag requested.\");\n"
1269 " MY(status_bits) = m_status_bits;\n"
1272 "void istream::lock_streambufs() {\n"
1274 " if (MY(mutex_lock) != 0) {\n"
1275 " unlock_streambufs();\n"
1276 " throw std::runtime_error(\"hddm_"
1277 << classPrefix <<
"::istream::lock_streambufs error - \"\n"
1278 " \"mutex lock requested when lock already held.\");\n"
1280 " if ((MY(status_bits) & k_bits_compression) == k_no_compression) {\n"
1281 " pthread_mutex_lock(&m_streambuf_mutex);\n"
1282 " MY(mutex_lock) = 1;\n"
1284 " else if ((MY(status_bits) & k_bits_compression) == k_z_compression) {\n"
1285 " ((xstream::z::istreambuf*)MY(xcmp))->set_streambuf_mutex(&m_streambuf_mutex);\n"
1286 " MY(mutex_lock) = 2;\n"
1288 " else if ((MY(status_bits) & k_bits_compression) == k_bz2_compression) {\n"
1289 " ((xstream::bz::istreambuf*)MY(xcmp))->set_streambuf_mutex(&m_streambuf_mutex);\n"
1290 " MY(mutex_lock) = 3;\n"
1293 " MY(mutex_lock) = -1;\n"
1297 "void istream::unlock_streambufs() {\n"
1299 " if (MY(mutex_lock) == 0) {\n"
1300 " throw std::runtime_error(\"hddm_"
1301 << classPrefix <<
"::istream::unlock_streambufs error - \"\n"
1302 " \"mutex unlock requested when lock not held.\");\n"
1304 " else if (MY(mutex_lock) == 1) {\n"
1305 " pthread_mutex_unlock(&m_streambuf_mutex);\n"
1307 " else if (MY(mutex_lock) == 2) {\n"
1308 " ((xstream::z::istreambuf*)MY(xcmp))->set_streambuf_mutex(0);\n"
1310 " else if (MY(mutex_lock) == 3) {\n"
1311 " ((xstream::bz::istreambuf*)MY(xcmp))->set_streambuf_mutex(0);\n"
1313 " MY(mutex_lock) = 0;\n"
1316 "istream &istream::operator>>(HDDM &record) {\n"
1318 " lock_streambufs();\n"
1319 " MY(event_size) = 0;\n"
1320 " while (MY(event_size) == 0) {\n"
1321 " update_streambufs();\n"
1322 " if (MY(status_bits) & (k_bz2_compression | k_z_compression)) {\n"
1323 " if (MY(status_bits) & k_can_reposition) {\n"
1324 " MY(istr)->clear();\n"
1325 " MY(istr)->read(MY(event_buffer),4);\n"
1326 " MY(bytes_read) += MY(istr)->gcount();\n"
1327 " if (!MY(istr)->good()) {\n"
1328 " unlock_streambufs();\n"
1329 " MY(hit_eof) = 1;\n"
1332 " if (MY(status_bits) & k_bz2_compression) {\n"
1333 " MY(last_start) = dynamic_cast<xstream::bz::istreambuf*>\n"
1334 " (MY(xcmp))->get_block_start();\n"
1335 " MY(last_offset) = dynamic_cast<xstream::bz::istreambuf*>\n"
1336 " (MY(xcmp))->get_block_offset();\n"
1339 " MY(last_start) = dynamic_cast<xstream::z::istreambuf*>\n"
1340 " (MY(xcmp))->get_block_start();\n"
1341 " MY(last_offset) = dynamic_cast<xstream::z::istreambuf*>\n"
1342 " (MY(xcmp))->get_block_offset();\n"
1344 " MY(last_offset) -= 4;\n"
1347 " MY(last_start) = 0;\n"
1348 " MY(last_offset) = 0;\n"
1352 " if (MY(next_start) > 0) {\n"
1353 " m_istr.seekg(MY(next_start), std::ios_base::beg);\n"
1354 " MY(istr)->clear();\n"
1355 " MY(last_start) = MY(next_start);\n"
1356 " MY(last_offset) = 0;\n"
1357 " MY(next_start) = 0;\n"
1360 " MY(last_start) = m_istr.tellg();\n"
1361 " MY(last_offset) = 0;\n"
1363 " MY(istr)->read(MY(event_buffer),4);\n"
1364 " MY(bytes_read) += MY(istr)->gcount();\n"
1365 " if (!MY(istr)->good()) {\n"
1366 " unlock_streambufs();\n"
1367 " MY(hit_eof) = 1;\n"
1371 " MY(hit_eof) = 0;\n"
1372 " MY(sbuf)->reset();\n"
1373 " *MY(xstr) >> MY(event_size);\n"
1374 " if (MY(event_size) == 1) {\n"
1375 " MY(istr)->read(MY(event_buffer)+4,4);\n"
1376 " MY(bytes_read) += MY(istr)->gcount();\n"
1377 " if (!MY(istr)->good()) {\n"
1378 " unlock_streambufs();\n"
1379 " throw std::runtime_error(\"hddm_"
1380 << classPrefix <<
"::istream::operator>> error -\"\n"
1381 " \" read error on token input!\");\n"
1384 " *MY(xstr) >> size;\n"
1385 " MY(istr)->read(MY(event_buffer)+8,size);\n"
1386 " MY(bytes_read) += MY(istr)->gcount();\n"
1387 " if (!MY(istr)->good()) {\n"
1388 " unlock_streambufs();\n"
1389 " throw std::runtime_error(\"hddm_"
1390 << classPrefix <<
"::istream::operator>> error -\"\n"
1391 " \" read error on token input!\");\n"
1393 " int format, flags;\n"
1394 " *MY(xstr) >> format >> flags;\n"
1395 " if (format != 0) {\n"
1396 " unlock_streambufs();\n"
1397 " throw std::runtime_error(\"hddm_"
1398 << classPrefix <<
"::istream::operator>> error - \"\n"
1399 " \"unsupported compression format!\");\n"
1401 " m_status_bits.store(flags);\n"
1402 " MY(event_size) = 0;\n"
1405 " if (MY(event_size)+8 > MY(event_buffer_size)) {\n"
1406 " delete MY(xstr);\n"
1407 " delete MY(sbuf);\n"
1408 " char *newbuf = new char[MY(event_buffer_size) = MY(event_size)+1000];\n"
1409 " MY(sbuf) = new istreambuffer(newbuf, MY(event_buffer_size));\n"
1410 " MY(xstr) = new xstream::xdr::istream(MY(sbuf));\n"
1411 " memcpy(newbuf,MY(event_buffer),4);\n"
1412 " delete [] MY(event_buffer);\n"
1413 " MY(event_buffer) = newbuf;\n"
1415 " MY(istr)->read(MY(event_buffer)+4,MY(event_size));\n"
1416 " MY(bytes_read) += MY(istr)->gcount();\n"
1417 " MY(records_read)++;\n"
1418 " if (!MY(istr)->good()) {\n"
1419 " unlock_streambufs();\n"
1420 " throw std::runtime_error(\"hddm_"
1421 << classPrefix <<
"::istream::operator>> error -\"\n"
1422 " \" read error in mid-record!\");\n"
1424 " if ((MY(status_bits) & k_crc32_integrity) != 0) {\n"
1425 " unsigned int recorded_crc;\n"
1426 " char crcbuf[10];\n"
1427 " istreambuffer sbuf(crcbuf,10);\n"
1428 " xstream::xdr::istream xstr(&sbuf);\n"
1429 " MY(istr)->read(crcbuf,4);\n"
1430 " MY(bytes_read) += MY(istr)->gcount();\n"
1431 " xstr >> recorded_crc;\n"
1432 " xstream::digest::crc32 crc;\n"
1433 " std::ostream out(&crc);\n"
1434 " out.write(MY(event_buffer),MY(event_size)+4);\n"
1436 " if (crc.digest() != recorded_crc) {\n"
1437 " char errmsg[] = \n"
1438 " \"WARNING: crc data integrity check failed\"\n"
1439 " \" on hddm_" << classPrefix <<
" input stream!\"\n"
1440 " \"\\nThis may be the result of a bug in the\"\n"
1441 " \" xstream library if you are analyzing a data\"\n"
1442 " \" file that was generated by code prior to svn\"\n"
1443 " \" rev 18530.\\nIf this concerns you, regenerate\"\n"
1444 " \" using a newer build of the sim-recon tools\"\n"
1445 " \" and it should go away.\\n\";\n"
1446 " if ((MY(status_bits) & 0x02) == 0) {\n"
1447 " std::cerr << errmsg << std::endl;\n"
1448 " MY(status_bits) |= 0x02;\n"
1450 " //unlock_streambufs();\n"
1451 " //throw std::runtime_error(\"hddm_"
1452 << classPrefix <<
"::istream::operator>> error -\"\n"
1453 " // \" crc check error on input stream!\");\n"
1456 " unlock_streambufs();\n"
1457 " if (MY(events_to_skip)) {\n"
1458 " --MY(events_to_skip);\n"
1459 " return *this >> record;\n"
1461 " MY(sbuf)->reset();\n"
1462 " MY(sequencing) = 0;\n"
1463 " MY(codon) = &MY(genome);\n"
1464 " *this >> (streamable&)record;\n"
1468 "ostream::ostream(std::ostream &src)\n"
1470 " m_status_bits(k_default_status)\n"
1472 " m_ostr << HDDM::DocumentString();\n"
1473 " if (!m_ostr.good()) {\n"
1474 " throw std::runtime_error(\"hddm_" + classPrefix +
1475 "::ostream::ostream(ostream) \"\n"
1476 " \"error - write error on header output!\");\n"
1478 " pthread_mutex_init(&m_streambuf_mutex,0);\n"
1479 " for (int i=0; i<threads::max_threads; ++i) {\n"
1480 " my_thread_private[i] = 0;\n"
1482 " init_private_data();\n"
1485 "ostream::~ostream() {\n"
1486 " pthread_mutex_destroy(&m_streambuf_mutex);\n"
1487 " for (int i=0; i<threads::max_threads; ++i) {\n"
1488 " thread_private_data *my_private = my_thread_private[i];\n"
1489 " if (my_private != 0) {\n"
1490 " if (MY(xstr)) {\n"
1491 " delete MY(xstr);\n"
1493 " if (MY(sbuf)) {\n"
1494 " delete MY(sbuf);\n"
1496 " if (MY(xcmp)) {\n"
1497 " MY(xcmp)->pubsync();\n"
1498 " MY(ostr)->rdbuf(m_ostr.rdbuf());\n"
1499 " delete MY(xcmp);\n"
1501 " if (MY(ostr)) {\n"
1502 " MY(ostr)->flush();\n"
1503 " delete MY(ostr);\n"
1505 " delete [] MY(event_buffer);\n"
1506 " delete my_private;\n"
1511 "void ostream::init_private_data() {\n"
1512 " int threadID = threads::getID();\n"
1513 " if (my_thread_private[threadID] == 0) {\n"
1514 " my_thread_private[threadID] = new thread_private_data;\n"
1517 " MY(event_buffer) = new char[MY(event_buffer_size) = 100000];\n"
1518 " MY(sbuf) = new ostreambuffer(MY(event_buffer),MY(event_buffer_size));\n"
1519 " MY(xstr) = new xstream::xdr::ostream(MY(sbuf));\n"
1520 " MY(ostr) = new std::ostream(m_ostr.rdbuf());\n"
1522 " MY(last_start) = 0;\n"
1523 " MY(last_offset) = 0;\n"
1524 " MY(records_written) = 0;\n"
1525 " MY(bytes_written) = 0;\n"
1526 " MY(status_bits) = 0;\n"
1527 " MY(mutex_lock) = 0;\n"
1530 "void ostream::setCompression(int flags) {\n"
1532 " int oldcmp = (int)m_status_bits & k_bits_compression;\n"
1533 " int newcmp = flags & k_bits_compression;\n"
1534 " if (oldcmp != newcmp) {\n"
1535 " m_status_bits.fetch_and(~k_bits_compression | flags);\n"
1536 " m_status_bits.fetch_or(k_bits_compression & flags);\n"
1537 " if (newcmp != 0)\n"
1538 " m_status_bits.fetch_or(k_can_reposition);\n"
1539 " MY(sbuf)->reset();\n"
1540 " *MY(xstr) << 1 << 8 << 0 << (int)m_status_bits;\n"
1541 " lock_streambufs();\n"
1542 " MY(ostr)->write(MY(sbuf)->getbuf(),MY(sbuf)->size());\n"
1543 " if (!MY(ostr)->good()) {\n"
1544 " unlock_streambufs();\n"
1545 " throw std::runtime_error(\"hddm_"
1546 << classPrefix <<
"::ostream::setCompression\"\n"
1547 " \" error - write error on token output!\");\n"
1549 " MY(ostr)->flush();\n"
1550 " update_streambufs();\n"
1551 " unlock_streambufs();\n"
1555 "void ostream::setIntegrityChecks(int flags) {\n"
1557 " int oldint = (int)m_status_bits & k_bits_integrity;\n"
1558 " int newint = flags & k_bits_integrity;\n"
1559 " if (oldint != newint) {\n"
1560 " m_status_bits.fetch_and(~k_bits_integrity | flags);\n"
1561 " m_status_bits.fetch_or(k_bits_integrity & flags);\n"
1562 " MY(sbuf)->reset();\n"
1563 " *MY(xstr) << 1 << 8 << 0 << (int)m_status_bits;\n"
1564 " lock_streambufs();\n"
1565 " MY(ostr)->write(MY(sbuf)->getbuf(),MY(sbuf)->size());\n"
1566 " if (!MY(ostr)->good()) {\n"
1567 " unlock_streambufs();\n"
1568 " throw std::runtime_error(\"hddm_"
1569 << classPrefix <<
"::ostream::setIntegrityChecks\"\n"
1570 " \" error - write error on token output!\");\n"
1572 " MY(ostr)->flush();\n"
1573 " update_streambufs();\n"
1574 " unlock_streambufs();\n"
1578 "streamposition ostream::getPosition() {\n"
1580 " streamposition pos;\n"
1581 " pos.block_start = MY(last_start);\n"
1582 " pos.block_start = MY(last_offset);\n"
1583 " pos.block_status = MY(status_bits);\n"
1587 "void ostream::update_streambufs() {\n"
1589 " if ((int)m_status_bits != MY(status_bits)) {\n"
1590 " configure_streambufs();\n"
1594 "void ostream::configure_streambufs() {\n"
1596 " int oldcmp = MY(status_bits) & k_bits_compression;\n"
1597 " int newcmp = (int)m_status_bits & k_bits_compression;\n"
1598 " if (oldcmp != newcmp) {\n"
1599 " if (oldcmp != k_no_compression) {\n"
1600 " MY(ostr)->rdbuf(m_ostr.rdbuf());\n"
1601 " delete MY(xcmp);\n"
1604 " if (newcmp == k_z_compression) {\n"
1605 " //std::cerr << \"output switched on z compression\" << std::endl;\n"
1606 " MY(xcmp) = new xstream::z::ostreambuf(m_ostr.rdbuf());\n"
1607 " MY(ostr)->rdbuf(MY(xcmp));\n"
1609 " else if (newcmp == k_bz2_compression) {\n"
1610 " //std::cerr << \"output switched on bz2 compression\" << std::endl;\n"
1611 " MY(xcmp )= new xstream::bz::ostreambuf(m_ostr.rdbuf());\n"
1612 " MY(ostr)->rdbuf(MY(xcmp));\n"
1614 " else if (newcmp != k_no_compression) {\n"
1615 " throw std::runtime_error(\"hddm_"
1616 << classPrefix <<
"::ostream::configure_streambufs error - \"\n"
1617 " \"unrecognized compression flag requested.\");\n"
1620 " MY(status_bits) = m_status_bits;\n"
1623 "void ostream::lock_streambufs() {\n"
1625 " if (MY(mutex_lock) != 0) {\n"
1626 " unlock_streambufs();\n"
1627 " throw std::runtime_error(\"hddm_"
1628 << classPrefix <<
"::ostream::lock_streambufs error - \"\n"
1629 " \"mutex lock requested when lock already held.\");\n"
1631 " if ((MY(status_bits) & k_bits_compression) == k_no_compression) {\n"
1632 " pthread_mutex_lock(&m_streambuf_mutex);\n"
1633 " MY(mutex_lock) = 1;\n"
1635 " else if ((MY(status_bits) & k_bits_compression) == k_z_compression) {\n"
1636 " ((xstream::z::ostreambuf*)MY(xcmp))->set_streambuf_mutex(&m_streambuf_mutex);\n"
1637 " MY(mutex_lock) = 2;\n"
1639 " else if ((MY(status_bits) & k_bits_compression) == k_bz2_compression) {\n"
1640 " ((xstream::bz::ostreambuf*)MY(xcmp))->set_streambuf_mutex(&m_streambuf_mutex);\n"
1641 " MY(mutex_lock) = 3;\n"
1644 " MY(mutex_lock) = -1;\n"
1648 "void ostream::unlock_streambufs() {\n"
1650 " if (MY(mutex_lock) == 0) {\n"
1651 " throw std::runtime_error(\"hddm_"
1652 << classPrefix <<
"::ostream::unlock_streambufs error - \"\n"
1653 " \"mutex unlock requested when lock not held.\");\n"
1655 " else if (MY(mutex_lock) == 1) {\n"
1656 " pthread_mutex_unlock(&m_streambuf_mutex);\n"
1658 " else if (MY(mutex_lock) == 2) {\n"
1659 " ((xstream::z::ostreambuf*)MY(xcmp))->set_streambuf_mutex(0);\n"
1661 " else if (MY(mutex_lock) == 3) {\n"
1662 " ((xstream::bz::ostreambuf*)MY(xcmp))->set_streambuf_mutex(0);\n"
1664 " MY(mutex_lock) = 0;\n"
1667 "int istream::getTag(const std::string &src, int start,\n"
1668 " std::string &tag, int &level)\n"
1671 " size_t p_btag = src.find(\"<\",start);\n"
1672 " size_t p_bline = src.find_last_of(\"\\n\",p_btag);\n"
1673 " if (p_bline == std::string::npos)\n"
1681 " level = (p_btag-p_bline)/2;\n"
1682 " size_t p_etag = p_btag;\n"
1683 " for (size_t quotes=0; p_etag < src.size(); ++p_etag) {\n"
1684 " if (src[p_etag] == '\"') {\n"
1685 " tag += \"\\\"\";\n"
1688 " else if (quotes/2*2 != quotes) {\n"
1689 " tag += src[p_etag];\n"
1691 " else if (src.find_first_of(\" \\t\\n\",p_etag) == 0) {\n"
1693 " p_etag = src.find_first_not_of(\" \\t\\n\",p_etag)-1;\n"
1695 " else if (src[p_etag] == '>') {\n"
1700 " tag += src[p_etag];\n"
1703 " if (p_etag == src.size()) {\n"
1704 " std::stringstream sstr;\n"
1705 " sstr << \"hddm_" + classPrefix +
"::istream::getTag\"\n"
1706 " << \" error - bad header format\" << std::endl\n"
1707 " << \" tag \" << tag << \" at position \" << start\n"
1709 " throw std::runtime_error(sstr.str());\n"
1711 " return p_etag+2;\n"
1714 "int istream::getEndTag(const std::string &src, int start,\n"
1715 " const std::string &tag)\n"
1717 " if (tag.rfind(\"/>\") == tag.size()-2) {\n"
1718 " return src.find(tag,start) + tag.size()+1;\n"
1721 " std::string etag = \"</\";\n"
1722 " etag += tag.substr(1,tag.find_first_of(' ')-1) + \">\";\n"
1723 " size_t p_etag = src.find(etag,start);\n"
1724 " size_t p_quote = src.find_first_of('\"',start);\n"
1725 " while (p_quote != std::string::npos && p_quote < p_etag) {\n"
1726 " p_quote = src.find_first_of('\"',p_quote+1);\n"
1727 " if (p_quote > p_etag) {\n"
1728 " p_etag = src.find(etag,p_quote+1);\n"
1730 " p_quote = src.find_first_of('\"',p_quote+1);\n"
1732 " if (p_etag == std::string::npos) {\n"
1733 " std::stringstream sstr;\n"
1734 " sstr << \"hddm_" + classPrefix +
"::istream::getEndTag\"\n"
1735 " << \" error - bad header format\" << std::endl\n"
1736 " << \" tag \" << tag << \" at position \" << start\n"
1738 " << \" end tag \" << etag << \" not found.\"\n"
1740 " throw std::runtime_error(sstr.str());\n"
1742 " return p_etag + etag.size()+1;\n"
1746 "void istream::collide(const std::string &itag, const std::string &rtag) {\n"
1747 " std::string itagname = itag.substr(1,itag.find(\" \")-1);\n"
1748 " std::string rtagname = rtag.substr(1,rtag.find(\" \")-1);\n"
1749 " std::string errmsg = \"hddm_" + classPrefix +
1750 "::istream::collide warning:\\n\"\n"
1751 " \"tag \" + itagname + \" in input file \"\n"
1752 " \"does not match c++ header hddm_" << classPrefix <<
".hpp\\n\"\n"
1753 " \" input file: \" + itag + \"\\n\"\n"
1754 " \" c++ header: \" + rtag + \"\\n\"\n"
1755 " \" === Tag \" + itagname + \" will be ignored,\"\n"
1756 " \" rebuild to cure the problem ===\";\n"
1757 " if (itagname != \"HDDM\") {\n"
1758 " std::cerr << errmsg << std::endl;\n"
1761 " throw std::runtime_error(errmsg);\n"
1765 "chromosome istream::synthesize(const std::string &src, int p_src,\n"
1766 " const std::string &ref, int p_ref)\n"
1768 " chromosome chrom;\n"
1769 " int slevel, rlevel;\n"
1770 " std::string stag, rtag;\n"
1771 " p_src = getTag(src,p_src,stag,slevel);\n"
1772 " p_ref = getTag(ref,p_ref,rtag,rlevel);\n"
1773 " std::string stagname = stag.substr(1,stag.find(\" \")-1);\n"
1774 " std::string rtagname = rtag.substr(1,rtag.find(\" \")-1);\n"
1775 " if (stagname != rtagname) {\n"
1776 " throw std::runtime_error(\"hddm_" + classPrefix +
1777 "::istream::synthesize error - matching algorithm error #2\");\n"
1779 " else if (!tags_match(stag,rtag)) {\n"
1780 " collide(stag,rtag);\n"
1784 " int p2_src, p2_ref;\n"
1785 " int s2level, r2level;\n"
1786 " std::string s2tag, r2tag;\n"
1787 " getTag(src,p2_src=p_src,s2tag,s2level);\n"
1788 " while (s2level > slevel) {\n"
1789 " codon *gene = new codon();\n"
1790 " std::string s2tagname = s2tag.substr(1,s2tag.find(\" \")-1);\n"
1791 " getTag(ref,p2_ref=p_ref,r2tag,r2level);\n"
1792 " int order_of_this_tag_in_ref = 1;\n"
1793 " while (r2level == s2level) {\n"
1794 " std::string r2tagname = r2tag.substr(1,r2tag.find(\" \")-1);\n"
1795 " if (s2tagname == r2tagname) {\n"
1796 " if (!tags_match(s2tag,r2tag)) {\n"
1797 " collide(s2tag,r2tag);\n"
1801 " gene->m_order = order_of_this_tag_in_ref;\n"
1803 " gene->m_sequence = synthesize(src,p2_src,ref,p2_ref);\n"
1806 " p2_ref = getEndTag(ref,p2_ref,r2tag);\n"
1807 " getTag(ref,p2_ref,r2tag,r2level);\n"
1808 " ++order_of_this_tag_in_ref;\n"
1810 " gene->m_tagname = s2tagname;\n"
1811 " chrom.push_back(*gene);\n"
1813 " p2_src = getEndTag(src,p2_src,s2tag);\n"
1814 " getTag(src,p2_src,s2tag,s2level);\n"
1820 XMLPlatformUtils::Terminate();
1827 XtString::size_type len = p.size();
1828 if (len > 3 && p.substr(len-3,3) ==
"tum")
1830 p.replace(len-3,3,
"ta");
1832 else if (len > 1 && p.substr(len-3,3) ==
"ies")
1834 p.replace(len-3,3,
"iesList");
1836 else if (len > 2 && p.substr(len-2,2) ==
"ex")
1838 p.replace(len-2,2,
"ices");
1840 else if (len > 2 && p.substr(len-2,2) ==
"sh")
1842 p.replace(len-2,2,
"shes");
1844 else if (len > 1 && p.substr(len-1,1) ==
"s")
1846 p.replace(len-1,1,
"ses");
1861 p[0] = toupper(p[0]);
1871 r[0] = toupper(r[0]);
1882 r[0] = toupper(r[0]);
1894 parentList_t::iterator iter;
1895 for (iter = list.begin(); iter != list.end(); ++iter, ++n)
1897 DOMElement *el = (DOMElement*)(*iter);
1899 if (cnameS == name) {
1912 if (el->getParentNode() == elref->getParentNode())
1915 <<
"hddm-cpp error: tag " <<
"\"" << tagS
1916 <<
"\" is duplicated within one context in xml document."
1921 DOMNamedNodeMap* oldAttr = elref->getAttributes();
1922 DOMNamedNodeMap* newAttr = el->getAttributes();
1923 unsigned int listLength = oldAttr->getLength();
1924 for (
unsigned int n = 0; n < listLength; n++)
1926 XtString nameS(oldAttr->item(n)->getNodeName());
1927 XtString oldS(elref->getAttribute(
X(nameS)));
1928 XtString newS(el->getAttribute(
X(nameS)));
1929 if (nameS ==
"minOccurs")
1933 else if (nameS ==
"maxOccurs")
1935 int maxold = (oldS ==
"unbounded")? INT_MAX : atoi(
S(oldS));
1936 int maxnew = (newS ==
"unbounded")? INT_MAX : atoi(
S(newS));
1937 if ((maxold < 2 && maxnew > 1) || (maxold > 1 && maxnew < 2))
1940 <<
"hddm-cpp error: inconsistent maxOccurs usage by tag "
1941 <<
"\"" << tagS <<
"\" in xml document." << std::endl;
1945 else if (newS != oldS)
1948 <<
"hddm-cpp error: inconsistent usage of attribute "
1949 <<
"\"" << nameS <<
"\" in tag "
1950 <<
"\"" << tagS <<
"\" in xml document." << std::endl;
1954 listLength = newAttr->getLength();
1955 for (
unsigned int n = 0; n < listLength; n++)
1957 XtString nameS(newAttr->item(n)->getNodeName());
1958 XtString oldS(elref->getAttribute(
X(nameS)));
1959 XtString newS(el->getAttribute(
X(nameS)));
1960 if (nameS ==
"minOccurs")
1964 else if (nameS ==
"maxOccurs")
1966 int maxold = (oldS ==
"unbounded")? INT_MAX : atoi(
S(oldS));
1967 int maxnew = (newS ==
"unbounded")? INT_MAX : atoi(
S(newS));
1968 if ((maxold < 2 && maxnew > 1) || (maxold > 1 && maxnew < 2))
1971 <<
"hddm-cpp error: inconsistent maxOccurs usage by tag "
1972 <<
"\"" << tagS <<
"\" in xml document." << std::endl;
1976 else if (newS != oldS)
1979 <<
"hddm-cpp error: inconsistent usage of attribute "
1980 <<
"\"" << nameS <<
"\" in tag "
1981 <<
"\"" << tagS <<
"\" in xml document." << std::endl;
1985 DOMNodeList* oldList = elref->getChildNodes();
1986 DOMNodeList* newList = el->getChildNodes();
1987 listLength = oldList->getLength();
1988 if (newList->getLength() != listLength)
1991 <<
"hddm-cpp error: inconsistent usage of tag "
1992 <<
"\"" << tagS <<
"\" in xml document." << std::endl;
1995 for (
unsigned int n = 0; n < listLength; n++)
1997 DOMNode* cont = oldList->item(n);
1998 XtString nameS(cont->getNodeName());
1999 short type = cont->getNodeType();
2000 if (type == DOMNode::ELEMENT_NODE)
2002 DOMNodeList* contList = el->getElementsByTagName(
X(nameS));
2003 if (contList->getLength() != 1)
2006 <<
"hddm-cpp error: inconsistent usage of tag "
2007 <<
"\"" << tagS <<
"\" in xml document." << std::endl;
2020 <<
": public HDDM_Element {" << std::endl
2021 <<
" public:" << std::endl;
2022 if (tagS ==
"HDDM") {
2023 hFile <<
" HDDM();" << std::endl;
2025 hFile <<
" ~" << tagS.
simpleType() <<
"();" << std::endl;
2027 std::map<XtString,XtString> attrList;
2028 DOMNamedNodeMap *myAttr = el->getAttributes();
2029 for (
unsigned int n = 0; n < myAttr->getLength(); n++)
2031 XtString attrS(myAttr->item(n)->getNodeName());
2032 XtString typeS(el->getAttribute(
X(attrS)));
2033 attrList[attrS] = typeS;
2035 parentList_t::iterator iter;
2036 for (iter = parents[tagS].begin(); iter != parents[tagS].end(); ++iter)
2038 DOMElement *hostEl = (DOMElement*)(*iter);
2039 XtString hostS(hostEl->getTagName());
2040 DOMNamedNodeMap *hostAttr = hostEl->getAttributes();
2041 for (
unsigned int n = 0; n < hostAttr->getLength(); n++)
2043 XtString attrS(hostAttr->item(n)->getNodeName());
2044 if (attrList.find(attrS) != attrList.end())
2048 XtString typeS(hostEl->getAttribute(
X(attrS)));
2049 attrList[attrS] = typeS;
2050 XtString getS(
"get"+attrS.simpleType());
2053 hFile <<
" int " << getS <<
"() const;" << std::endl;
2055 else if (typeS ==
"long")
2057 hFile <<
" int64_t " << getS <<
"() const;" << std::endl;
2059 else if (typeS ==
"float")
2061 hFile <<
" float " << getS <<
"() const;" << std::endl;
2063 else if (typeS ==
"double")
2065 hFile <<
" double " << getS <<
"() const;" << std::endl;
2067 else if (typeS ==
"boolean")
2069 hFile <<
" bool " << getS <<
"() const;" << std::endl;
2071 else if (typeS ==
"string")
2073 hFile <<
" std::string " << getS <<
"() const;" << std::endl;
2075 else if (typeS ==
"anyURI")
2077 hFile <<
" std::string " << getS <<
"() const;" << std::endl;
2079 else if (typeS ==
"Particle_t")
2081 hFile <<
" Particle_t " << getS <<
"() const;" << std::endl;
2085 hFile <<
" int " << getS <<
"() const;" << std::endl;
2089 hFile <<
" int64_t " << getS <<
"() const;" << std::endl;
2093 hFile <<
" float " << getS <<
"() const;" << std::endl;
2097 hFile <<
" double " << getS <<
"() const;" << std::endl;
2101 hFile <<
" bool " << getS <<
"() const;" << std::endl;
2103 else if (
guessType(typeS) ==
"Particle_t")
2105 hFile <<
" Particle_t " << getS <<
"() const;" << std::endl;
2109 hFile <<
" std::string " << getS <<
"() const;" << std::endl;
2114 myAttr = el->getAttributes();
2115 for (
unsigned int n = 0; n < myAttr->getLength(); n++)
2117 XtString attrS(myAttr->item(n)->getNodeName());
2118 XtString typeS(el->getAttribute(
X(attrS)));
2119 XtString getS(
"get" + attrS.simpleType());
2120 XtString setS(
"set" + attrS.simpleType());
2123 hFile <<
" int " << getS <<
"() const;" << std::endl
2124 <<
" void " << setS <<
"(int " << attrS <<
");" << std::endl;
2126 else if (typeS ==
"long")
2128 hFile <<
" int64_t " << getS <<
"() const;" << std::endl
2129 <<
" void " << setS <<
"(int64_t " << attrS <<
");" << std::endl;
2131 else if (typeS ==
"float")
2133 hFile <<
" float " << getS <<
"() const;" << std::endl
2134 <<
" void " << setS <<
"(float " << attrS <<
");" << std::endl;
2136 else if (typeS ==
"double")
2138 hFile <<
" double " << getS <<
"() const;" << std::endl
2139 <<
" void " << setS <<
"(double " << attrS <<
");" << std::endl;
2141 else if (typeS ==
"boolean")
2143 hFile <<
" bool " << getS <<
"() const;" << std::endl
2144 <<
" void " << setS <<
"(bool " << attrS <<
");" << std::endl;
2146 else if (typeS ==
"string")
2148 hFile <<
" std::string " << getS <<
"() const;" << std::endl
2149 <<
" void " << setS <<
"(const std::string &" << attrS <<
");"
2152 else if (typeS ==
"anyURI")
2154 hFile <<
" std::string " << getS <<
"() const;" << std::endl
2155 <<
" void " << setS <<
"(const std::string &" << attrS <<
");"
2158 else if (typeS ==
"Particle_t")
2160 hFile <<
" Particle_t " << getS <<
"() const;" << std::endl
2161 <<
" void " << setS <<
"(Particle_t " << attrS <<
");" << std::endl;
2165 hFile <<
" int " << getS <<
"() const;" << std::endl;
2169 hFile <<
" int64_t " << getS <<
"() const;" << std::endl;
2173 hFile <<
" float " << getS <<
"() const;" << std::endl;
2177 hFile <<
" double " << getS <<
"() const;" << std::endl;
2181 hFile <<
" bool " << getS <<
"() const;" << std::endl;
2183 else if (
guessType(typeS) ==
"Particle_t")
2185 hFile <<
" Particle_t " << getS <<
"() const;" << std::endl;
2189 hFile <<
" std::string " << getS <<
"() const;" << std::endl;
2193 if (tagS ==
"HDDM") {
2194 parentTable_t::iterator piter;
2195 for (piter = parents.begin(); piter != parents.end(); ++piter)
2198 if (cnameS !=
"HDDM" && element_in_list(cnameS,children[tagS]) == -1)
2200 hFile <<
" " << cnameS.
listType() <<
" get"
2206 parentList_t::iterator citer;
2207 for (citer = children[tagS].begin(); citer != children[tagS].end(); ++citer)
2209 DOMElement *childEl = (DOMElement*)(*citer);
2210 XtString cnameS(childEl->getTagName());
2211 XtString repS(childEl->getAttribute(
X(
"maxOccurs")));
2212 int rep = (repS ==
"unbounded")? INT_MAX : atoi(
S(repS));
2213 hFile <<
" " << cnameS.
simpleType() <<
" &get"
2215 << ((rep > 1)?
"(int index=0);" :
"();") << std::endl;
2216 hFile <<
" " << cnameS.
listType() <<
" &get"
2218 hFile <<
" " << cnameS.
listType() <<
" add"
2220 <<
"(int count=1, int start=-1);" << std::endl;
2221 hFile <<
" void delete"
2223 <<
"(int count=-1, int start=0);" << std::endl;
2226 hFile <<
" const void *getAttribute(const std::string &name,"
2227 <<
" hddm_type *atype=0) const;\n"
2228 <<
" std::string toString(int indent=0);\n"
2229 <<
" std::string toXML(int indent=0);\n";
2233 hFile <<
" void clear();" << std::endl;
2234 parentTable_t::iterator piter;
2235 for (piter = parents.begin(); piter != parents.end(); ++piter)
2238 if (cnameS !=
"HDDM") {
2239 hFile <<
" friend class " << cnameS.
simpleType() <<
";"
2243 hFile <<
" static std::string DocumentString();" << std::endl;
2244 hFile <<
" private:" << std::endl;
2248 hFile <<
" friend class HDDM_ElementList<"
2250 <<
" friend class HDDM_ElementLink<"
2252 hFile <<
" private:" << std::endl
2254 <<
"(HDDM_Element *parent=0);" << std::endl;
2257 hFile <<
" void streamer(istream &istr);" << std::endl
2258 <<
" void streamer(ostream &ostr);" << std::endl;
2260 for (
unsigned int n = 0; n < myAttr->getLength(); n++)
2262 XtString attrS(myAttr->item(n)->getNodeName());
2263 XtString typeS(el->getAttribute(
X(attrS)));
2266 hFile <<
" int m_" << attrS <<
";" << std::endl;
2268 else if (typeS ==
"long")
2270 hFile <<
" int64_t m_" << attrS <<
";" << std::endl;
2272 else if (typeS ==
"float")
2274 hFile <<
" float m_" << attrS <<
";" << std::endl;
2276 else if (typeS ==
"double")
2278 hFile <<
" double m_" << attrS <<
";" << std::endl;
2280 else if (typeS ==
"boolean")
2282 hFile <<
" int m_" << attrS <<
";" << std::endl;
2284 else if (typeS ==
"string")
2286 hFile <<
" std::string m_" << attrS <<
";" << std::endl;
2288 else if (typeS ==
"anyURI")
2290 hFile <<
" std::string m_" << attrS <<
";" << std::endl;
2292 else if (typeS ==
"Particle_t")
2294 hFile <<
" int m_" << attrS <<
";" << std::endl;
2298 if (tagS ==
"HDDM") {
2299 parentTable_t::iterator piter;
2300 for (piter = parents.begin(); piter != parents.end(); ++piter)
2303 if (dnameS !=
"HDDM") {
2304 hFile <<
" std::list<" << dnameS.
simpleType()
2305 <<
"*> m_" << dnameS <<
"_plist;" << std::endl;
2310 for (citer = children[tagS].begin(); citer != children[tagS].end(); ++citer)
2312 DOMElement *childEl = (DOMElement*)(*citer);
2313 XtString cnameS(childEl->getTagName());
2314 XtString repS(childEl->getAttribute(
X(
"maxOccurs")));
2315 int rep = (repS ==
"unbounded")? INT_MAX : atoi(
S(repS));
2316 hFile <<
" " << ((rep > 1)? cnameS.listType() : cnameS.linkType())
2318 << ((rep > 1)?
"_list;" :
"_link;") << std::endl;
2321 hFile <<
"};" << std::endl << std::endl;
2325 hFile <<
"typedef HDDM_ElementList<"
2327 << tagS.
listType() <<
";" << std::endl
2328 <<
"typedef HDDM_ElementLink<"
2331 << std::endl << std::endl;
2342 parentList_t::iterator piter;
2343 parents[tagS].insert(parents[tagS].begin(),
2344 parentList.begin(),parentList.end());
2345 std::vector<DOMElement*>::iterator iter;
2346 for (iter = tagList.begin(); iter != tagList.end(); iter++)
2348 DOMElement* targEl = *iter;
2349 XtString targS(targEl->getTagName());
2352 checkConsistency(el,targEl);
2357 parentList.push_back(el);
2358 DOMNodeList* contList = el->getChildNodes();
2359 int contLength = contList->getLength();
2360 for (
int c = 0;
c < contLength;
c++)
2362 DOMNode* cont = contList->item(
c);
2363 short type = cont->getNodeType();
2364 if (type == DOMNode::ELEMENT_NODE)
2366 DOMElement* contEl = (DOMElement*) cont;
2367 XtString contS(contEl->getTagName());
2368 children[tagS].push_back(contEl);
2369 constructGroup(contEl);
2372 parentList.pop_back();
2374 tagList.push_back(el);
2378 std::vector<DOMElement*>::iterator iter;
2379 for (iter = tagList.begin(); iter != tagList.end(); iter++)
2381 writeClassdef(*iter);
2393 hFile <<
"inline " << tagS.
simpleType() <<
"::"
2395 <<
" : HDDM_Element()";
2399 hFile <<
"inline " << tagS.
simpleType() <<
"::"
2400 << tagS.
simpleType() <<
"(HDDM_Element *parent)" << std::endl
2401 <<
" : HDDM_Element(parent)";
2403 DOMNamedNodeMap *myAttr = el->getAttributes();
2404 for (
unsigned int n = 0; n < myAttr->getLength(); n++)
2406 XtString attrS(myAttr->item(n)->getNodeName());
2407 XtString typeS(el->getAttribute(
X(attrS)));
2410 hFile <<
"," << std::endl <<
" m_" << attrS <<
"(0)";
2412 else if (typeS ==
"long")
2414 hFile <<
"," << std::endl <<
" m_" << attrS <<
"(0)";
2416 else if (typeS ==
"float")
2418 hFile <<
"," << std::endl <<
" m_" << attrS <<
"(0)";
2420 else if (typeS ==
"double")
2422 hFile <<
"," << std::endl <<
" m_" << attrS <<
"(0)";
2424 else if (typeS ==
"boolean")
2426 hFile <<
"," << std::endl <<
" m_" << attrS <<
"(0)";
2428 else if (typeS ==
"string")
2430 hFile <<
"," << std::endl <<
" m_" << attrS <<
"(\"\")";
2432 else if (typeS ==
"anyURI")
2434 hFile <<
"," << std::endl <<
" m_" << attrS <<
"(\"\")";
2436 else if (typeS ==
"Particle_t")
2438 hFile <<
"," << std::endl <<
" m_" << attrS <<
"(0)";
2450 parentList_t::iterator citer;
2451 for (citer = children[tagS].begin();
2452 citer != children[tagS].end();
2455 DOMElement *childEl = (DOMElement*)(*citer);
2456 XtString cnameS(childEl->getTagName());
2457 XtString repS(childEl->getAttribute(
X(
"maxOccurs")));
2463 hFile <<
"," << std::endl <<
" m_" << cnameS
2468 for (citer = children[tagS].begin();
2469 citer != children[tagS].end();
2472 DOMElement *childEl = (DOMElement*)(*citer);
2473 XtString cnameS(childEl->getTagName());
2474 XtString repS(childEl->getAttribute(
X(
"maxOccurs")));
2475 int rep = (repS ==
"unbounded")? INT_MAX : atoi(
S(repS));
2476 const char *myHost = (tagS==
"HDDM" ?
"this->":
"m_host->");
2478 hFile <<
"," << std::endl <<
" m_" << cnameS
2479 << ((rep > 1)?
"_list" :
"_link")
2480 <<
"(&" << hostS <<
"m_" << cnameS <<
"_plist," << std::endl
2482 << hostS <<
"m_" << cnameS <<
"_plist.end()," << std::endl
2484 << hostS <<
"m_" << cnameS <<
"_plist.end()," << std::endl
2490 hFile << std::endl <<
"{" << std::endl
2491 <<
" m_host = this;" << std::endl
2492 <<
"}" << std::endl << std::endl;
2496 hFile << std::endl <<
"{}" << std::endl << std::endl;
2499 hFile <<
"inline " << tagS.
simpleType() <<
"::~"
2501 << ((children[tagS].size())?
"\n" :
"");
2502 for (citer = children[tagS].begin();
2503 citer != children[tagS].end();
2506 DOMElement *childEl = (DOMElement*)(*citer);
2507 XtString cnameS(childEl->getTagName());
2509 <<
"();" << std::endl;
2511 hFile <<
"}" << std::endl << std::endl;
2513 std::map<XtString,XtString> attrList;
2514 myAttr = el->getAttributes();
2515 for (
unsigned int n = 0; n < myAttr->getLength(); n++)
2517 XtString attrS(myAttr->item(n)->getNodeName());
2518 XtString typeS(el->getAttribute(
X(attrS)));
2519 attrList[attrS] = typeS;
2521 parentList_t::iterator iter;
2522 for (iter = parents[tagS].begin(); iter != parents[tagS].end(); ++iter)
2524 DOMElement *hostEl = (DOMElement*)(*iter);
2525 DOMNamedNodeMap *hostAttr = hostEl->getAttributes();
2526 for (
unsigned int n = 0; n < hostAttr->getLength(); n++)
2528 XtString attrS(hostAttr->item(n)->getNodeName());
2529 if (attrList.find(attrS) != attrList.end())
2533 XtString typeS(hostEl->getAttribute(
X(attrS)));
2534 attrList[attrS] = typeS;
2535 XtString getS(
"get" + attrS.simpleType());
2539 <<
"::" << getS <<
"() const {" << std::endl
2540 <<
" return *(int*)m_parent->getAttribute(\""
2541 << attrS <<
"\");" << std::endl
2542 <<
"}" << std::endl << std::endl;
2544 else if (typeS ==
"long")
2546 hFile <<
"inline int64_t " << tagS.
simpleType()
2547 <<
"::" << getS <<
"() const {" << std::endl
2548 <<
" return *(int64_t*)m_parent->getAttribute(\""
2549 << attrS <<
"\");" << std::endl
2550 <<
"}" << std::endl << std::endl;
2552 else if (typeS ==
"float")
2554 hFile <<
"inline float " << tagS.
simpleType()
2555 <<
"::" << getS <<
"() const {" << std::endl
2556 <<
" return *(float*)m_parent->getAttribute(\""
2557 << attrS <<
"\");" << std::endl
2558 <<
"}" << std::endl << std::endl;
2560 else if (typeS ==
"double")
2562 hFile <<
"inline double " << tagS.
simpleType()
2563 <<
"::" << getS <<
"() const {" << std::endl
2564 <<
" return *(double*)m_parent->getAttribute(\""
2565 << attrS <<
"\");" << std::endl
2566 <<
"}" << std::endl << std::endl;
2568 else if (typeS ==
"boolean")
2571 <<
"::" << getS <<
"() const {" << std::endl
2572 <<
" return *(bool*)m_parent->getAttribute(\""
2573 << attrS <<
"\");" << std::endl
2574 <<
"}" << std::endl << std::endl;
2576 else if (typeS ==
"string")
2578 hFile <<
"inline std::string " << tagS.
simpleType()
2579 <<
"::" << getS <<
"() const {" << std::endl
2580 <<
" return *(const std::string*)m_parent->getAttribute(\""
2581 << attrS <<
"\");" << std::endl
2582 <<
"}" << std::endl << std::endl;
2584 else if (typeS ==
"anyURI")
2586 hFile <<
"inline std::string " << tagS.
simpleType()
2587 <<
"::" << getS <<
"() const {" << std::endl
2588 <<
" return *(const std::string*)m_parent->getAttribute(\""
2589 << attrS <<
"\");" << std::endl
2590 <<
"}" << std::endl << std::endl;
2592 else if (typeS ==
"Particle_t")
2594 hFile <<
"inline Particle_t " << tagS.
simpleType()
2595 <<
"::" << getS <<
"() const {" << std::endl
2596 <<
" return *(Particle_t*)m_parent->getAttribute(\""
2597 << attrS <<
"\");" << std::endl
2598 <<
"}" << std::endl << std::endl;
2603 <<
"::" << getS <<
"() const {" << std::endl
2604 <<
" return *(int*)m_parent->getAttribute(\""
2605 << attrS <<
"\");" << std::endl
2606 <<
"}" << std::endl << std::endl;
2610 hFile <<
"inline int64_t " << tagS.
simpleType()
2611 <<
"::" << getS <<
"() const {" << std::endl
2612 <<
" return *(long long int*)m_parent->getAttribute(\""
2613 << attrS <<
"\");" << std::endl
2614 <<
"}" << std::endl << std::endl;
2618 hFile <<
"inline float " << tagS.
simpleType()
2619 <<
"::" << getS <<
"() const {" << std::endl
2620 <<
" return *(float*)m_parent->getAttribute(\""
2621 << attrS <<
"\");" << std::endl
2622 <<
"}" << std::endl << std::endl;
2626 hFile <<
"inline double " << tagS.
simpleType()
2627 <<
"::" << getS <<
"() const {" << std::endl
2628 <<
" return *(double*)m_parent->getAttribute(\""
2629 << attrS <<
"\");" << std::endl
2630 <<
"}" << std::endl << std::endl;
2635 <<
"::" << getS <<
"() const {" << std::endl
2636 <<
" return *(bool*)m_parent->getAttribute(\""
2637 << attrS <<
"\");" << std::endl
2638 <<
"}" << std::endl << std::endl;
2640 else if (
guessType(typeS) ==
"Particle_t")
2642 hFile <<
"inline Particle_t " << tagS.
simpleType()
2643 <<
"::" << getS <<
"() const {" << std::endl
2644 <<
" return *(Particle_t*)m_parent->getAttribute(\""
2645 << attrS <<
"\");" << std::endl
2646 <<
"}" << std::endl << std::endl;
2650 hFile <<
"inline std::string " << tagS.
simpleType()
2651 <<
"::" << getS <<
"() const {" << std::endl
2652 <<
" return *(std::string*)m_parent->getAttribute(\""
2653 << attrS <<
"\");" << std::endl
2654 <<
"}" << std::endl << std::endl;
2659 for (
unsigned int n = 0; n < myAttr->getLength(); n++)
2661 XtString attrS(myAttr->item(n)->getNodeName());
2662 XtString typeS(el->getAttribute(
X(attrS)));
2663 XtString getS(
"get" + attrS.simpleType());
2664 XtString setS(
"set" + attrS.simpleType());
2667 hFile <<
"inline int " << tagS.
simpleType() <<
"::" << getS
2668 <<
"() const {" << std::endl
2669 <<
" return m_" << attrS <<
";" << std::endl
2670 <<
"}" << std::endl << std::endl
2671 <<
"inline void " << tagS.
simpleType() <<
"::" << setS
2672 <<
"(int " << attrS <<
") {" << std::endl
2673 <<
" m_" << attrS <<
" = " << attrS <<
";" << std::endl
2674 <<
"}" << std::endl << std::endl;
2676 else if (typeS ==
"long")
2678 hFile <<
"inline int64_t " << tagS.
simpleType() <<
"::" << getS
2679 <<
"() const {" << std::endl
2680 <<
" return m_" << attrS <<
";" << std::endl
2681 <<
"}" << std::endl << std::endl
2682 <<
"inline void " << tagS.
simpleType() <<
"::" << setS
2683 <<
"(int64_t " << attrS <<
") {" << std::endl
2684 <<
" m_" << attrS <<
" = " << attrS <<
";" << std::endl
2685 <<
"}" << std::endl << std::endl;
2687 else if (typeS ==
"float")
2689 hFile <<
"inline float " << tagS.
simpleType() <<
"::" << getS
2690 <<
"() const {" << std::endl
2691 <<
" return m_" << attrS <<
";" << std::endl
2692 <<
"}" << std::endl << std::endl
2693 <<
"inline void " << tagS.
simpleType() <<
"::" << setS
2694 <<
"(float " << attrS <<
") {" << std::endl
2695 <<
" m_" << attrS <<
" = " << attrS <<
";" << std::endl
2696 <<
"}" << std::endl << std::endl;
2698 else if (typeS ==
"double")
2700 hFile <<
"inline double " << tagS.
simpleType() <<
"::" << getS
2701 <<
"() const {" << std::endl
2702 <<
" return m_" << attrS <<
";" << std::endl
2703 <<
"}" << std::endl << std::endl
2704 <<
"inline void " << tagS.
simpleType() <<
"::" << setS
2705 <<
"(double " << attrS <<
") {" << std::endl
2706 <<
" m_" << attrS <<
" = " << attrS <<
";" << std::endl
2707 <<
"}" << std::endl << std::endl;
2709 else if (typeS ==
"boolean")
2711 hFile <<
"inline bool " << tagS.
simpleType() <<
"::" << getS
2712 <<
"() const {" << std::endl
2713 <<
" return m_" << attrS <<
";" << std::endl
2714 <<
"}" << std::endl << std::endl
2715 <<
"inline void " << tagS.
simpleType() <<
"::" << setS
2716 <<
"(bool " << attrS <<
") {" << std::endl
2717 <<
" m_" << attrS <<
" = " << attrS <<
";" << std::endl
2718 <<
"}" << std::endl << std::endl;
2720 else if (typeS ==
"string")
2722 hFile <<
"inline std::string " << tagS.
simpleType() <<
"::" << getS
2723 <<
"() const {" << std::endl
2724 <<
" return m_" << attrS <<
";" << std::endl
2725 <<
"}" << std::endl << std::endl
2726 <<
"inline void " << tagS.
simpleType() <<
"::" << setS
2727 <<
"(const std::string &" << attrS <<
") {" << std::endl
2728 <<
" m_" << attrS <<
" = " << attrS <<
";" << std::endl
2729 <<
"}" << std::endl << std::endl;
2731 else if (typeS ==
"anyURI")
2733 hFile <<
"inline std::string " << tagS.
simpleType() <<
"::" << getS
2734 <<
"() const {" << std::endl
2735 <<
" return m_" << attrS <<
";" << std::endl
2736 <<
"}" << std::endl << std::endl
2737 <<
"inline void " << tagS.
simpleType() <<
"::" << setS
2738 <<
"(const std::string &" << attrS <<
") {" << std::endl
2739 <<
" m_" << attrS <<
" = " << attrS <<
";" << std::endl
2740 <<
"}" << std::endl << std::endl;
2742 else if (typeS ==
"Particle_t")
2744 hFile <<
"inline Particle_t " << tagS.
simpleType() <<
"::" << getS
2745 <<
"() const {" << std::endl
2746 <<
" return (Particle_t)m_" << attrS <<
";" << std::endl
2747 <<
"}" << std::endl << std::endl
2748 <<
"inline void " << tagS.
simpleType() <<
"::" << setS
2749 <<
"(Particle_t " << attrS <<
") {" << std::endl
2750 <<
" m_" << attrS <<
" = " << attrS <<
";" << std::endl
2751 <<
"}" << std::endl << std::endl;
2755 hFile <<
"inline int " << tagS.
simpleType() <<
"::" << getS
2756 <<
"() const {" << std::endl
2757 <<
" return " << typeS <<
";" << std::endl
2758 <<
"}" << std::endl << std::endl;
2762 hFile <<
"inline int64_t " << tagS.
simpleType() <<
"::" << getS
2763 <<
"() const {" << std::endl
2764 <<
" return " << typeS <<
"LL;" << std::endl
2765 <<
"}" << std::endl << std::endl;
2769 hFile <<
"inline float " << tagS.
simpleType() <<
"::" << getS
2770 <<
"() const {" << std::endl
2771 <<
" return " << typeS <<
";" << std::endl
2772 <<
"}" << std::endl << std::endl;
2776 hFile <<
"inline double " << tagS.
simpleType() <<
"::" << getS
2777 <<
"() const {" << std::endl
2778 <<
" return " << typeS <<
";" << std::endl
2779 <<
"}" << std::endl << std::endl;
2783 hFile <<
"inline bool " << tagS.
simpleType() <<
"::" << getS
2784 <<
"() const {" << std::endl
2785 <<
" return " << typeS <<
";" << std::endl
2786 <<
"}" << std::endl << std::endl;
2788 else if (
guessType(typeS) ==
"Particle_t")
2790 hFile <<
"inline Particle_t " << tagS.
simpleType()
2791 <<
"::" << getS <<
"() const {" << std::endl
2794 <<
"}" << std::endl << std::endl;
2798 hFile <<
"inline std::string " << tagS.simpleType()
2799 <<
"::" << getS <<
"() const {" << std::endl
2800 <<
" return \"" << typeS <<
"\";" << std::endl
2801 <<
"}" << std::endl << std::endl;
2807 hFile <<
"inline void HDDM::clear() {" << std::endl;
2808 for (citer = children[tagS].begin();
2809 citer != children[tagS].end();
2812 DOMElement *childEl = (DOMElement*)(*citer);
2813 XtString cnameS(childEl->getTagName());
2815 <<
"();" << std::endl;
2817 hFile <<
"}" << std::endl << std::endl;
2819 hFile <<
"inline const void *" << tagS.
simpleType()
2820 <<
"::getAttribute(const std::string &name,\n"
2822 <<
"hddm_type *atype) const {" << std::endl;
2823 for (
unsigned int n = 0; n < myAttr->getLength(); n++)
2825 XtString attrS(myAttr->item(n)->getNodeName());
2826 XtString typeS(el->getAttribute(
X(attrS)));
2827 hFile <<
" if (name == \"" << attrS <<
"\") {\n"
2828 <<
" if (atype != 0)\n";
2831 hFile <<
" *atype = k_hddm_int;\n";
2833 else if (typeS ==
"long")
2835 hFile <<
" *atype = k_hddm_long;\n";
2837 else if (typeS ==
"float")
2839 hFile <<
" *atype = k_hddm_float;\n";
2841 else if (typeS ==
"double")
2843 hFile <<
" *atype = k_hddm_double;\n";
2845 else if (typeS ==
"boolean")
2847 hFile <<
" *atype = k_hddm_boolean;\n";
2849 else if (typeS ==
"string")
2851 hFile <<
" *atype = k_hddm_string;\n";
2853 else if (typeS ==
"anyURI")
2855 hFile <<
" *atype = k_hddm_anyURI;\n";
2857 else if (typeS ==
"Particle_t")
2859 hFile <<
" *atype = k_hddm_Particle_t;\n";
2863 hFile <<
" *atype = k_hddm_int;\n"
2864 <<
" static int m_" << attrS
2865 <<
" = get" << attrS.
simpleType() <<
"();\n";
2869 hFile <<
" *atype = k_hddm_long;\n"
2870 <<
" static long m_" << attrS
2871 <<
" = get" << attrS.
simpleType() <<
"();\n";
2875 hFile <<
" *atype = k_hddm_float;\n"
2876 <<
" static float m_" << attrS
2877 <<
" = get" << attrS.
simpleType() <<
"();\n";
2881 hFile <<
" *atype = k_hddm_double;\n"
2882 <<
" static double m_" << attrS
2883 <<
" = get" << attrS.
simpleType() <<
"();\n";
2887 hFile <<
" *atype = k_hddm_boolean;\n"
2888 <<
" static int m_" << attrS
2889 <<
" = get" << attrS.
simpleType() <<
"();\n";
2891 else if (
guessType(typeS) ==
"Particle_t")
2893 hFile <<
" *atype = k_hddm_Particle_t;\n"
2894 <<
" static Particle_t m_" << attrS
2895 <<
" = get" << attrS.
simpleType() <<
"();\n";
2899 hFile <<
" *atype = k_hddm_unknown;\n"
2900 <<
" static std::string m_" << attrS
2901 <<
" = get" << attrS.
simpleType() <<
"();\n";
2903 hFile <<
" return &m_" << attrS <<
";\n"
2908 hFile <<
" return m_parent->getAttribute(name, atype);" << std::endl;
2912 hFile <<
" return 0;" << std::endl;
2914 hFile <<
"}" << std::endl << std::endl;
2917 <<
"::toString(int indent) {\n"
2918 <<
" std::stringstream ostr;\n"
2919 <<
" for (int n=0; n < indent; ++n)\n"
2920 <<
" ostr << \" \";\n"
2921 <<
" ostr << \"" << tagS <<
"\"\n";
2922 for (
unsigned int n = 0; n < myAttr->getLength(); n++)
2924 XtString attrS(myAttr->item(n)->getNodeName());
2925 XtString typeS(el->getAttribute(
X(attrS)));
2926 if (typeS ==
"int" || typeS ==
"long" ||
2927 typeS ==
"float" || typeS ==
"double")
2929 cFile <<
" << \" " << attrS <<
"=\" << "
2930 <<
"m_" << attrS << std::endl;
2932 else if (typeS ==
"boolean")
2934 cFile <<
" << \" " << attrS <<
"=\" << "
2935 <<
"((m_" << attrS <<
" == 0)? \"true\" : \"false\")"
2938 else if (typeS ==
"string" || typeS ==
"anyURI")
2940 cFile <<
" << \" " << attrS <<
"=\" << "
2941 <<
"\"\\\"\" << m_" << attrS <<
" << \"\\\"\"" << std::endl;
2943 else if (typeS ==
"Particle_t")
2945 cFile <<
" << \" " << attrS <<
"=\" << "
2946 <<
"ParticleType((Particle_t)m_" << attrS <<
")" << std::endl;
2949 cFile <<
" << std::endl;" << std::endl;
2950 for (citer = children[tagS].begin(); citer != children[tagS].end(); ++citer)
2952 DOMElement *childEl = (DOMElement*)(*citer);
2953 XtString cnameS(childEl->getTagName());
2954 XtString repS(childEl->getAttribute(
X(
"maxOccurs")));
2955 int rep = (repS ==
"unbounded")? INT_MAX : atoi(
S(repS));
2958 cFile <<
" int " << cnameS.
listType() <<
"Count=0;" << std::endl
2959 <<
" for (" << cnameS.
listType() <<
"::iterator it = "
2960 <<
"m_" << cnameS <<
"_list.begin();" << std::endl
2962 <<
"m_" << cnameS <<
"_list.end(); ++it)" << std::endl
2963 <<
" {" << std::endl
2964 <<
" if (++" << cnameS.
listType() <<
"Count > "
2965 <<
"m_" << cnameS <<
"_list.size()) {" << std::endl
2966 <<
" throw std::runtime_error(\"hddm_"
2968 "list improperly terminated!\");" << std::endl
2969 <<
" }" << std::endl
2970 <<
" ostr << it->toString(indent + 2);" << std::endl
2971 <<
" }" << std::endl;
2975 cFile <<
" if (! m_" << cnameS <<
"_link.empty()) {\n"
2976 <<
" ostr << m_" << cnameS <<
"_link.begin()"
2977 <<
"->toString(indent + 2);\n"
2978 <<
" }" << std::endl;
2981 cFile <<
" return ostr.str();" << std::endl
2982 <<
"}" << std::endl << std::endl;
2984 cFile <<
"std::string " << tagS.simpleType()
2985 <<
"::toXML(int indent) {\n"
2986 <<
" std::stringstream ostr;\n"
2987 <<
" for (int n=0; n < indent; ++n)\n"
2988 <<
" ostr << \" \";\n"
2989 <<
" ostr << \"<" << tagS <<
"\"\n";
2990 for (
unsigned int n = 0; n < myAttr->getLength(); n++)
2992 XtString attrS(myAttr->item(n)->getNodeName());
2993 XtString typeS(el->getAttribute(
X(attrS)));
2994 if (attrS ==
"minOccurs" || attrS ==
"maxOccurs")
2998 if (typeS ==
"boolean")
3000 cFile <<
" << \" " << attrS <<
"=\" << "
3001 <<
"((m_" << attrS <<
" == 0)? \"\\\"true\\\"\" : \"\\\"false\\\"\")"
3004 else if (typeS ==
"Particle_t")
3006 cFile <<
" << \" " << attrS <<
"=\\\"\" << "
3007 <<
"ParticleType((Particle_t)m_" << attrS <<
") << \"\\\"\""
3012 cFile <<
" << \" " << attrS <<
"=\" << "
3014 <<
"() << \"\\\"\"" << std::endl;
3017 if (children[tagS].
size() > 0)
3019 cFile <<
" << \">\" << std::endl;" << std::endl;
3023 cFile <<
" << \" />\" << std::endl;" << std::endl;
3025 for (citer = children[tagS].begin(); citer != children[tagS].end(); ++citer)
3027 DOMElement *childEl = (DOMElement*)(*citer);
3028 XtString cnameS(childEl->getTagName());
3029 XtString repS(childEl->getAttribute(
X(
"maxOccurs")));
3030 int rep = (repS ==
"unbounded")? INT_MAX : atoi(
S(repS));
3033 cFile <<
" int " << cnameS.
listType() <<
"Count=0;" << std::endl
3034 <<
" for (" << cnameS.
listType() <<
"::iterator it = "
3035 <<
"m_" << cnameS <<
"_list.begin();" << std::endl
3037 <<
"m_" << cnameS <<
"_list.end(); ++it)" << std::endl
3038 <<
" {" << std::endl
3039 <<
" if (++" << cnameS.
listType() <<
"Count > "
3040 <<
"m_" << cnameS <<
"_list.size()) {" << std::endl
3041 <<
" throw std::runtime_error(\"hddm_"
3043 "list improperly terminated!\");" << std::endl
3044 <<
" }" << std::endl
3045 <<
" ostr << it->toXML(indent + 2);" << std::endl
3046 <<
" }" << std::endl;
3050 cFile <<
" if (! m_" << cnameS <<
"_link.empty()) {\n"
3051 <<
" ostr << m_" << cnameS <<
"_link.begin()"
3052 <<
"->toXML(indent + 2);" << std::endl
3053 <<
" }" << std::endl;
3056 if (children[tagS].
size() > 0)
3058 cFile <<
" for (int n=0; n < indent; ++n)\n"
3059 <<
" ostr << \" \";\n"
3060 <<
" ostr << \"</" << tagS <<
">\"\n"
3061 <<
" << std::endl;" << std::endl;
3063 cFile <<
" return ostr.str();" << std::endl
3064 <<
"}" << std::endl << std::endl;
3066 for (citer = children[tagS].begin(); citer != children[tagS].end(); ++citer)
3068 DOMElement *childEl = (DOMElement*)(*citer);
3069 XtString cnameS(childEl->getTagName());
3070 XtString repS(childEl->getAttribute(
X(
"maxOccurs")));
3071 int rep = (repS ==
"unbounded")? INT_MAX : atoi(
S(repS));
3074 hFile <<
"inline " << cnameS.
simpleType() <<
" &"
3076 <<
"(int index) {" << std::endl
3077 <<
" return m_" << cnameS <<
"_list(index);" << std::endl
3078 <<
"}" << std::endl << std::endl
3079 <<
"inline " << cnameS.
listType() <<
" &"
3081 <<
"() {" << std::endl
3082 <<
" return m_" << cnameS <<
"_list;" << std::endl
3083 <<
"}" << std::endl << std::endl
3084 <<
"inline " << cnameS.
listType() <<
" "
3086 <<
"(int count, int start) {" << std::endl
3087 <<
" return m_" << cnameS <<
"_list.add(count,start);"
3088 << std::endl <<
"}" << std::endl << std::endl
3089 <<
"inline void " << tagS.
simpleType() <<
"::delete"
3091 <<
"(int count, int start) {" << std::endl
3092 <<
" m_" << cnameS <<
"_list.del(count,start);"
3093 << std::endl <<
"}" << std::endl << std::endl;
3097 hFile <<
"inline " << cnameS.
simpleType() <<
" &"
3099 <<
"() {" << std::endl
3100 <<
" return m_" << cnameS <<
"_link.front();" << std::endl
3101 <<
"}" << std::endl << std::endl
3102 <<
"inline " << cnameS.
listType() <<
" &"
3104 <<
"() {" << std::endl
3105 <<
" return m_" << cnameS <<
"_link;" << std::endl
3106 <<
"}" << std::endl << std::endl
3107 <<
"inline " << cnameS.
listType() <<
" "
3109 <<
"(int count, int start) {" << std::endl
3110 <<
" return m_" << cnameS <<
"_link.add(count,start);"
3111 << std::endl <<
"}" << std::endl << std::endl
3112 <<
"inline void " << tagS.
simpleType() <<
"::delete"
3114 <<
"(int count, int start) {" << std::endl
3115 <<
" m_" << cnameS <<
"_link.del(count,start);"
3116 << std::endl <<
"}" << std::endl << std::endl;
3122 parentTable_t::iterator piter;
3123 for (piter = parents.begin(); piter != parents.end(); ++piter)
3126 if (cnameS !=
"HDDM" && element_in_list(cnameS,children[tagS]) == -1)
3128 hFile <<
"inline " << cnameS.
listType() <<
" "
3130 << std::endl <<
" return " << cnameS.
listType()
3131 <<
"(&m_" << cnameS <<
"_plist," << std::endl
3133 <<
"m_" << cnameS <<
"_plist.begin()," << std::endl
3135 <<
"m_" << cnameS <<
"_plist.end());" << std::endl
3136 <<
"}" << std::endl << std::endl;
3146 std::vector<DOMElement*>::iterator iter;
3147 for (iter = tagList.begin(); iter != tagList.end(); iter++)
3149 writeClassimp(*iter);
3159 std::vector<XtString> attrV;
3160 DOMNamedNodeMap *myAttr = el->getAttributes();
3161 for (
unsigned int n = 0; n < myAttr->getLength(); n++)
3163 XtString attrS(myAttr->item(n)->getNodeName());
3164 XtString typeS(el->getAttribute(
X(attrS)));
3165 if (typeS ==
"int" || typeS ==
"long" || typeS ==
"float" ||
3166 typeS ==
"double" || typeS ==
"boolean" || typeS ==
"string" ||
3167 typeS ==
"anyURI" || typeS ==
"Particle_t")
3169 attrV.push_back(attrS);
3173 std::vector<XtString> contV;
3174 DOMNodeList* contList = el->getChildNodes();
3175 int contListLength = contList->getLength();
3176 for (
int c = 0;
c < contListLength;
c++)
3178 DOMNode* node = contList->item(
c);
3179 if (node->getNodeType() == DOMNode::ELEMENT_NODE)
3181 DOMElement *contEl = (DOMElement*)node;
3182 XtString contS(contEl->getTagName());
3183 XtString repS(contEl->getAttribute(
X(
"maxOccurs")));
3184 int rep = (repS ==
"unbounded")? INT_MAX : atoi(
S(repS));
3185 contV.push_back(contS + ((rep > 1)?
"_list" :
"_link"));
3189 hFile <<
"inline void " << tagS.simpleType() <<
"::streamer"
3190 <<
"(istream &istr) {" << std::endl;
3192 hFile <<
" *istr.getXDRistream()";
3193 for (
unsigned int n=0; n < attrV.size(); ++n)
3195 hFile <<
" >> m_" << attrV[n];
3197 hFile <<
";" << std::endl;
3201 for (
unsigned int n=0; n < contV.size(); ++n)
3203 hFile <<
" >> m_" << contV[n];
3205 hFile <<
";" << std::endl;
3207 hFile <<
"}" << std::endl << std::endl;
3209 hFile <<
"inline void " << tagS.simpleType() <<
"::streamer"
3210 <<
"(ostream &ostr) {" << std::endl;
3212 hFile <<
" *ostr.getXDRostream()";
3213 for (
unsigned int n=0; n < attrV.size(); ++n)
3215 hFile <<
" << m_" << attrV[n];
3217 hFile <<
";" << std::endl;
3221 for (
unsigned int n=0; n < contV.size(); ++n)
3223 hFile <<
" << m_" << contV[n];
3225 hFile <<
";" << std::endl;
3227 hFile <<
"}" << std::endl << std::endl;
3232 std::vector<DOMElement*>::iterator iter;
3233 for (iter = tagList.begin(); iter != tagList.end(); ++iter)
3235 writeStreamers(*iter);
3244 "inline istream::thread_private_data *istream::lookup_private_data() {\n"
3245 " thread_private_data *my_private = my_thread_private[threads::getID()];\n"
3246 " if (my_private != 0)\n"
3247 " return my_private;\n"
3248 " init_private_data();\n"
3249 " return my_thread_private[threads::ID];\n"
3252 "inline ostream::thread_private_data *ostream::lookup_private_data() {\n"
3253 " thread_private_data *my_private = my_thread_private[threads::getID()];\n"
3254 " if (my_private != 0)\n"
3255 " return my_private;\n"
3256 " init_private_data();\n"
3257 " return my_thread_private[threads::ID];\n"
3260 "inline void istream::skip(int count) {\n"
3262 " MY(events_to_skip) = count;\n"
3265 "inline bool istream::eof() {\n"
3267 " return MY(hit_eof);\n"
3270 "inline bool istream::operator!() {\n"
3274 "inline istream::operator void*() {\n"
3276 " if (MY(hit_eof))\n"
3282 "inline int istream::getCompression() const {\n"
3283 " return (int)m_status_bits & k_bits_compression;\n"
3286 "inline int ostream::getCompression() const {\n"
3287 " return (int)m_status_bits & k_bits_compression;\n"
3290 "inline int istream::getIntegrityChecks() const {\n"
3291 " return (int)m_status_bits & k_bits_integrity;\n"
3294 "inline int istream::getBytesRead() const {\n"
3296 " for (int i=1; i < threads::max_threads; ++i)\n"
3297 " if (my_thread_private[i])\n"
3298 " bytes += my_thread_private[i]->m_bytes_read;\n"
3302 "inline int istream::getRecordsRead() const {\n"
3303 " int records = 0;\n"
3304 " for (int i=1; i < threads::max_threads; ++i)\n"
3305 " if (my_thread_private[i])\n"
3306 " records += my_thread_private[i]->m_records_read;\n"
3307 " return records;\n"
3310 "inline int ostream::getIntegrityChecks() const {\n"
3311 " return (int)m_status_bits & k_bits_integrity;\n"
3314 "inline int ostream::getBytesWritten() const {\n"
3316 " for (int i=1; i < threads::max_threads; ++i)\n"
3317 " if (my_thread_private[i])\n"
3318 " bytes += my_thread_private[i]->m_bytes_written;\n"
3322 "inline int ostream::getRecordsWritten() const {\n"
3323 " int records = 0;\n"
3324 " for (int i=1; i < threads::max_threads; ++i)\n"
3325 " if (my_thread_private[i])\n"
3326 " records += my_thread_private[i]->m_records_written;\n"
3327 " return records;\n"
3330 "inline istream &istream::operator>>(streamable &object) {\n"
3332 " if (MY(sequencing)) {\n"
3333 " MY(codon)->m_target.push_back(&object);\n"
3337 " *MY(xstr) >> size;\n"
3338 " if (size > 0) {\n"
3339 " std::streampos start = MY(sbuf)->tellg();\n"
3340 " sequencer(object);\n"
3341 " MY(sbuf)->seekg(start+(std::streamoff)size);\n"
3347 "inline void istream::reset_sequencer() {\n"
3349 " MY(sequencing) = 0;\n"
3352 "inline void istream::sequencer(streamable &object) {\n"
3354 " MY(sequencing) = 1;\n"
3355 " MY(codon)->m_target.clear();\n"
3356 " object.streamer(*this);\n"
3357 " if (MY(sequencing)) {\n"
3358 " MY(sequencing) = 0;\n"
3359 " codon &gene = *MY(codon);\n"
3360 " streamable null_streamable;\n"
3361 " gene.m_target.push_front(&null_streamable);\n"
3362 " chromosome::iterator iter;\n"
3363 " for (iter = gene.m_sequence.begin();\n"
3364 " iter != gene.m_sequence.end();\n"
3367 " MY(codon) = &(*iter);\n"
3368 " *this >> *gene.m_target[iter->m_order];\n"
3370 " MY(codon) = &gene;\n"
3374 "inline ostream &ostream::operator<<(HDDM &record) {\n"
3376 " MY(sbuf)->reset();\n"
3377 " *this << (streamable&)record;\n"
3378 " while (MY(sbuf)->size() == MY(event_buffer_size)) {\n"
3379 " delete MY(xstr);\n"
3380 " delete MY(sbuf);\n"
3381 " char *newbuf = new char[MY(event_buffer_size) *= 2];\n"
3382 " MY(sbuf) = new ostreambuffer(newbuf, MY(event_buffer_size));\n"
3383 " MY(xstr) = new xstream::xdr::ostream(MY(sbuf));\n"
3384 " delete [] MY(event_buffer);\n"
3385 " MY(event_buffer) = newbuf;\n"
3386 " *this << (streamable&)record;\n"
3388 " lock_streambufs();\n"
3389 " update_streambufs();\n"
3390 " if ((MY(status_bits) & k_crc32_integrity) != 0) {\n"
3391 " xstream::digest::crc32 crc;\n"
3392 " std::ostream out(&crc);\n"
3393 " out.write(MY(sbuf)->getbuf(),MY(sbuf)->size());\n"
3395 " unsigned int crc32 = crc.digest();\n"
3396 " *MY(xstr) << crc32;\n"
3398 " MY(ostr)->write(MY(sbuf)->getbuf(),MY(sbuf)->size());\n"
3399 " if (!MY(ostr)->good()) {\n"
3400 " unlock_streambufs();\n"
3401 " throw std::runtime_error(\"hddm_"
3402 <<
classPrefix <<
"::ostream::operator<< error - \"\n"
3403 " \"write error on event output!\");\n"
3405 " if (MY(status_bits) & k_bz2_compression) {\n"
3406 " MY(last_start) = ((xstream::bz::ostreambuf*)MY(xcmp))->get_block_start();\n"
3407 " MY(last_offset) = ((xstream::bz::ostreambuf*)MY(xcmp))->get_block_offset();\n"
3409 " else if (MY(status_bits) & k_z_compression) {\n"
3410 " MY(last_start) = ((xstream::z::ostreambuf*)MY(xcmp))->get_block_start();\n"
3411 " MY(last_offset) = ((xstream::z::ostreambuf*)MY(xcmp))->get_block_offset();\n"
3414 " MY(last_start) = m_ostr.tellp();\n"
3415 " MY(last_offset) = 0;\n"
3417 " unlock_streambufs();\n"
3418 " MY(bytes_written) += MY(sbuf)->size();\n"
3419 " MY(records_written)++;\n"
3423 "inline ostream &ostream::operator<<(streamable &object) {\n"
3425 " *MY(xstr) << 0;\n"
3426 " std::streampos start = MY(sbuf)->tellp();\n"
3427 " object.streamer(*this);\n"
3428 " std::streampos end = MY(sbuf)->tellp();\n"
3429 " MY(sbuf)->seekp(start-std::streamoff(4));\n"
3430 " *MY(xstr) << (int)(end-start);\n"
3431 " MY(sbuf)->seekp(end);\n"
3441 static int indent = 0;
3443 for (
int n = 0; n < indent; n++)
3449 hFile <<
"<" << tagS;
3450 DOMNamedNodeMap* attrList = el->getAttributes();
3451 int attrListLength = attrList->getLength();
3452 for (
int a = 0; a < attrListLength; a++)
3454 DOMNode* node = attrList->item(a);
3455 XtString nameS(node->getNodeName());
3456 XtString valueS(node->getNodeValue());
3457 hFile <<
" " << nameS <<
"=\\\"" << valueS <<
"\\\"";
3460 DOMNodeList* contList = el->getChildNodes();
3461 int contListLength = contList->getLength();
3462 if (contListLength > 0)
3464 hFile <<
">\\n\"" << std::endl;
3466 for (
int c = 0;
c < contListLength;
c++)
3468 DOMNode* node = contList->item(
c);
3469 if (node->getNodeType() == DOMNode::ELEMENT_NODE)
3471 DOMElement* contEl = (DOMElement*) node;
3472 constructDocument(contEl);
3477 for (
int n = 0; n < indent; n++)
3481 hFile <<
"</" << tagS <<
">\\n\"" << std::endl;
3485 hFile <<
" />\\n\"" << std::endl;
3491 const char *
str = literal.c_str();
3494 long long int llvalue = strtoll(str,&endptr,0);
3495 if (errno == 0 && *endptr == 0) {
3497 int lvalue = strtol(str,&endptr,0);
3498 if (errno == 0 && *endptr == 0 && lvalue == llvalue) {
3506 strtof(str,&endptr);
3507 if (errno == 0 && *endptr == 0) {
3511 strtod(str,&endptr);
3512 if (errno == 0 && *endptr == 0) {
3515 if (literal ==
"true" || literal ==
"false") {
3519 return "Particle_t";
3521 if (XMLUri::isValidURI(
false,
X(literal))) {
3529 for (
int p=0; p<100; ++p) {
int element_in_list(XtString &name, parentList_t list)
void constructGroup(DOMElement *el)
std::string guessType(const std::string &literal)
xercesc::DOMDocument * buildDOMDocument(const XString &xmlFile, bool keep)
void constructIOstreams(DOMElement *el)
void checkConsistency(DOMElement *el, DOMElement *elref)
XtString(const XString &x)
void writeStreamers(DOMElement *el)
static char * ParticleType(Particle_t p)
xercesc::DOMDocument * parseInputDocument(const XString &xmlFile, bool keep)
std::vector< DOMNode * > parentList_t
XtString(const XtString &t)
void constructDocument(DOMElement *el)
Particle_t lookupParticle(const std::string &name)
void writeClassimp(DOMElement *el)
void constructMethods(DOMElement *el)
XtString(const std::string &s)
void writeClassdef(DOMElement *el)
std::map< const XtString, parentList_t > parentTable_t
int main(int argc, char *argv[])
void constructStreamers(DOMElement *el)