/* MXL - a simple language for creating tables of data stored in C++ containers written by Jared Bruni ( jared@lostsidedead.biz ) under the GNU GPL */ #ifndef __MXL__H__ #define __MXL__H__ #include #include #include #include #include #include #include #include #include typedef void *(*mxlfunc)(void *); class tag_body { public: tag_body(); std::map tag; int tags_present; std::string field_name; }; typedef std::map::iterator fulltag; typedef std::vector > mxlArray; typedef std::map::iterator subtag; template class mxl_iterator { Container container; unsigned int offset; public: tag_body members; mxl_iterator(); mxl_iterator(Container &c); Container &operator=(Container &c); Container &operator=(mxl_iterator &c); Container &operator++(); Container &operator++(int); Container &operator--(); Container &operator--(int); tag_body &operator*(); tag_body *operator->(); bool operator!=(mxl_iterator &c); bool operator!=(int x); bool operator==(mxl_iterator &c); bool operator==(int x); bool operator<(mxl_iterator &c); bool operator<(int x); bool operator>(mxl_iterator &c); void assign(mxl_iterator &c); void lookup(); bool locateTag(std::string str); void start() { offset = 0; } int stop() { return container.size(); } }; class mxlParser { public: typedef mxl_iterator iterator; mxlParser(); mxlParser(std::string str); int parseMXL(std::string str); int parseMXL_file(std::string file_name); void printAscii(std::ostream& out); void printHTML(std::ostream& out); void printMXL(std::ostream &out); void printMXL_byIndex(std::ostream &out); void printHTML_byIndex(std::ostream &out); void clear(); std::string getstringfromkey(std::string tag, std::string key); std::string operator()(std::string tag, std::string key); std::map::iterator begin_key(std::string tag); std::map::iterator end_key(std::string tag); tag_body &getkeybyindex(const unsigned int i); tag_body &operator[](int i) { return tags[tag_set[i]]; } unsigned int getkeybyindex_size(); std::map& getTags() { return tags; } bool create_tag(std::string); bool fetchArray(mxlArray &v); subtag begin_mxl(int index, mxlArray &v); subtag end_mxl(int index, mxlArray &v); const unsigned int size() const { return tag_set.size(); } std::vector< std::string > tag_set; protected: int grabTag(std::string name, mascToken *token,std::string str); int getNextToken(mascToken *token, std::string str); std::map tags; int tag_count; }; template mxl_iterator::mxl_iterator() { offset = 0; } template mxl_iterator::mxl_iterator(Container &c) { offset = 0; container = c; } template Container &mxl_iterator::operator=(Container &c) { container = c; return *this; } template void mxl_iterator::assign(mxl_iterator &c) { c = c.container; offset = c.offset; } template Container &mxl_iterator::operator=(mxl_iterator &c) { assign(c); return *this; } template Container &mxl_iterator::operator++() { if(offset < container.size()) offset++; lookup(); return *this; } template Container &mxl_iterator::operator--() { if(offset > 0) offset--; lookup(); } template Container &mxl_iterator::operator++(int) { if(offset < container.size()) ++offset; lookup(); } template Container &mxl_iterator::operator--(int) { if(offset > 0) --offset; lookup(); } template void mxl_iterator::lookup() { if(offset < container.size()) members = container[offset]; } template tag_body &mxl_iterator::operator*() { if(offset < container.size()) members = container[offset]; return members; } template tag_body *mxl_iterator::operator->() { if(offset < container.size()) members = container[offset]; return &members; } template bool mxl_iterator::operator!=(mxl_iterator &c) { if(offset != c.offset) return true; return false; } template bool mxl_iterator::operator==(mxl_iterator &c) { if(offset == c.offset) return true; return false; } template bool mxl_iterator::operator<(mxl_iterator &c) { if(offset < c.offset) return true; return false; } template bool mxl_iterator::operator>(mxl_iterator &c) { if(offset > c.offset) return true; return false; } template bool mxl_iterator::locateTag(std::string name) { unsigned int i = 0; bool found = false; for(i = 0; i < container.tag_set.size(); i++) { if(container.tag_set[i] == name) { found = true; break; } } if(found == false) return false; offset = i; lookup(); return found; } template bool mxl_iterator::operator<(int x) { if(offset < x) return true; return false; } template bool mxl_iterator::operator==(int x) { if(offset == x) return true; return false; } template bool mxl_iterator::operator!=(int x) { if(offset != x) return true; return false; } #endif