void emitEncodedSizeNohash() { const char *sn = ls.structname.shortname.c_str(); emit(0, "int %s::_getEncodedSizeNoHash() const", sn); emit(0, "{"); if(ls.members.size() == 0) { emit(1, "return 0;"); emit(0,"}"); emit(0,""); return; } emit(1, "int enc_size = 0;"); for (auto& lm : ls.members) { auto& mtn = lm.type.fullname; auto *mn = lm.membername.c_str(); int ndim = (int)lm.dimensions.size(); if (ZCMGen::isPrimitiveType(mtn) && mtn != "string") { emitStart(1, "enc_size += "); for(int n = 0; n < ndim-1; n++) { auto& dim = lm.dimensions[n]; emitContinue("%s%s * ", dimSizePrefix(dim.size).c_str(), dim.size.c_str()); } if(ndim > 0) { auto& dim = lm.dimensions[ndim-1]; emitEnd("__%s_encoded_array_size(NULL, %s%s);", mtn.c_str(), dimSizePrefix(dim.size).c_str(), dim.size.c_str()); } else { emitEnd("__%s_encoded_array_size(NULL, 1);", mtn.c_str()); } } else { for(int n = 0; n < ndim; n++) { auto& dim = lm.dimensions[n]; emit(1+n, "for (int a%d = 0; a%d < %s%s; a%d++) {", n, n, dimSizePrefix(dim.size).c_str(), dim.size.c_str(), n); } emitStart(ndim + 1, "enc_size += this->%s", mn); for(int i = 0; i < ndim; i++) emitContinue("[a%d]", i); if (mtn == "string") { emitEnd(".size() + 4 + 1;"); } else { emitEnd("._getEncodedSizeNoHash();"); } for(int n = ndim-1; n >= 0; n--) { emit(1 + n, "}"); } } } emit(1, "return enc_size;"); emit(0,"}"); emit(0,""); }
bool list_display( void ) { bool breturn = true; editLink = listTemplate.getParagraph("hotcolumn"); editLink = editLink.replace("$prog$","store_ui.cgi"); hotCol=2; emitFilter( "store_ui.cgi", // program name "Store" ); // Label emitHeadings("Id|<a style='color:blue;' href='store_ui.cgi?sort=MarketerName'>Marketer</a>|" "<a style='color:blue;' href='store_ui.cgi?sort=StoreName'>Store</a>|" "<a style='color:blue;' href='store_ui.cgi?sort=Featured'>Featured</a>|" "<a style='color:blue;' href='store_ui.cgi?sort=Enabled'>Enabled</a>"); getFilteredData( "StoreID, MarketerName, StoreName," "case Featured when 1 then 'Yes' else 'No' end as Featured," "case Enabled when 1 then 'Yes' else 'No' end as Enabled", "Store s inner join Marketer m on s.MarketerID = m.MarketerID", "StoreName like '$filter$%'", "StoreName" ); emitData(); emitNavigation("store_ui.cgi"); emitEnd(); return breturn; }
bool list_display( void ) { bool breturn = true; editLink = listTemplate.getParagraph("hotcolumn"); editLink = editLink.replace("$prog$","users_ui.cgi"); hotCol=1; emitFilter( "users_ui.cgi", // program name " <B>FILTER</B>" ); // Label emitHeadings("Id|User Name"); if( !oLogin.SiteAdmin() ) { addedCriteria = " group_id = "; addedCriteria += oLogin.GroupId(); } getFilteredData( "id, concat( first, ' ', last) as name", "users", "last like '$filter$%'", "last, first" ); emitData(); emitNavigation("users_ui.cgi"); emitEnd(); return breturn; }
bool list_display( void ) { bool breturn = true; hotCol=-1; // no heat string sql; Composite_Query_Obj qry; qry.key(atoll(Query_Id.c_str())); if( qry.get_data() ) { sql = qry.asSQL(false); if( sql.find("limit") == string::npos ) sql += " limit 2 "; getData( sql ); emitHeadings(); emitData(); } else { webIO << "No data in Query - Key: " << Query_Id << endl; } emitEnd(); return breturn; }
void _encodeRecursive(ZCMMember& lm, int depth, int extraIndent) { auto& mtn = lm.type.fullname; int indent = extraIndent + 1 + depth; int ndims = (int)lm.dimensions.size(); // primitive array if (depth+1 == ndims && ZCMGen::isPrimitiveType(mtn) && mtn != "string") { auto& dim = lm.dimensions[depth]; emitStart(indent, "tlen = __%s_encode_%sarray(buf, offset + pos, maxlen - pos, &this->%s", mtn.c_str(), zcm.gopt->getBool("little-endian-encoding") ? "little_endian_" : "", lm.membername.c_str()); for(int i = 0; i < depth; i++) emitContinue("[a%d]", i); emitEnd("[0], %s%s);", dimSizePrefix(dim.size).c_str(), dim.size.c_str()); emit(indent, "if(tlen < 0) return tlen; else pos += tlen;"); return; } if(depth == ndims) { if(mtn == "string") { emitStart(indent, "char* __cstr = (char*) this->%s", lm.membername.c_str()); for(int i = 0; i < depth; i++) emitContinue("[a%d]", i); emitEnd(".c_str();"); emit(indent, "tlen = __string_encode_%sarray(buf, offset + pos, maxlen - pos, &__cstr, 1);", zcm.gopt->getBool("little-endian-encoding") ? "little_endian_" : ""); } else { emitStart(indent, "tlen = this->%s", lm.membername.c_str()); for(int i = 0; i < depth; i++) emitContinue("[a%d]", i); emitEnd("._encodeNoHash(buf, offset + pos, maxlen - pos);"); } emit(indent, "if(tlen < 0) return tlen; else pos += tlen;"); return; } auto& dim = lm.dimensions[depth]; emit(indent, "for (int a%d = 0; a%d < %s%s; a%d++) {", depth, depth, dimSizePrefix(dim.size).c_str(), dim.size.c_str(), depth); _encodeRecursive(lm, depth+1, extraIndent); emit(indent, "}"); }
bool list_display( void ) { bool breturn = true; editLink = listTemplate.getParagraph("hotcolumn"); editLink = editLink.replace("$prog$","category_form.cgi").replace("_self","editPane"); hotCol=1; emitHeadings("ID|CATEGORY <a target='editPane' href='category_form.cgi'>New</a>"); getData( "select Id, Name from Category order by Cat_Order" ); emitData(); emitEnd(); return breturn; }
bool list_display( string key ) { bool breturn = true; string sql = "select Id, Name from Sub_Category where Category_Id = "; sql += key; sql += " order by Sub_Order"; editLink = listTemplate.getParagraph("hotcolumn"); editLink = editLink.replace("$prog$","sub_category_form.cgi").replace("_self","editPane"); hotCol=1; string heading = "ID|SUB-CATEGORY " "<a target='editPane' href='sub_category_form.cgi?Category_Id="; heading+=key; heading+="'>New</a>"; emitHeadings(heading); getData( sql ); emitData(); emitEnd(); return breturn; }
bool list_display( void ) { bool breturn = true; editLink = listTemplate.getParagraph("hotcolumn"); editLink = editLink.replace("$prog$","category_ui.cgi"); hotCol=1; emitFilter( "category_ui.cgi", // program name "Category" ); // Label emitHeadings("Id|Category Name"); getFilteredData( "CategoryID, CategoryName", "Category", "CategoryName like '$filter$%'", "CategoryName" ); emitData(); emitNavigation("category_ui.cgi"); emitEnd(); return breturn; }
bool list_display( void ) { bool breturn = true; editLink = listTemplate.getParagraph("hotcolumn"); editLink = editLink.replace("$prog$","roles_ui.cgi"); hotCol=1; emitFilter( "roles_ui.cgi", // program name " <B>FILTER</B>" ); // Label emitHeadings("Id|Role Name"); getFilteredData( "id, name", "roles", "name like '$filter$%'", "name" ); emitData(); emitNavigation("roles_ui.cgi"); emitEnd(); return breturn; }
bool list_display( void ) { bool breturn = true; editLink = listTemplate.getParagraph("hotcolumn"); editLink = editLink.replace("$prog$","group_sites_ui.cgi"); hotCol=1; emitFilter( "group_sites_ui.cgi", // program name " <B>FILTER</B>" ); // Label emitHeadings("Id|Group|Site"); getFilteredData( "gs.id, g.name, s.name", "group_sites gs inner join groups g on gs.group_id=g.id " "inner join metasite.sites s on gs.site_id = s.id ", "g.name like '$filter$%'", "g.name,s.name" ); emitData(); emitNavigation("group_sites_ui.cgi"); emitEnd(); return breturn; }
void _decodeRecursive(ZCMMember& lm, int depth) { auto& mtn = lm.type.fullname; auto *mn = lm.membername.c_str(); int ndims = (int)lm.dimensions.size(); // primitive array if (depth+1 == ndims && ZCMGen::isPrimitiveType(mtn) && mtn != "string") { auto& dim = lm.dimensions[depth]; int decodeIndent = 1 + depth; if(!lm.isConstantSizeArray()) { emit(1 + depth, "if(%s > 0) {", dimSizeAccessor(dim.size).c_str()); emitStart(2 + depth, "this->%s", mn); for(int i = 0; i < depth; i++) emitContinue("[a%d]", i); emitEnd(".resize(%s);", dimSizeAccessor(dim.size).c_str()); decodeIndent++; } emitStart(decodeIndent, "tlen = __%s_decode_%sarray(buf, offset + pos, maxlen - pos, &this->%s", mtn.c_str(), zcm.gopt->getBool("little-endian-encoding") ? "little_endian_" : "", mn); for(int i = 0; i < depth; i++) emitContinue("[a%d]", i); emitEnd("[0], %s);", dimSizeAccessor(dim.size).c_str()); emit(decodeIndent, "if(tlen < 0) return tlen; else pos += tlen;"); if (!lm.isConstantSizeArray()) { emit(1 + depth, "}"); } } else if(depth == ndims) { if (mtn == "string") { emit(1 + depth, "int32_t __elem_len;"); emit(1 + depth, "tlen = __int32_t_decode_%sarray(buf, offset + pos, maxlen - pos, &__elem_len, 1);", zcm.gopt->getBool("little-endian-encoding") ? "little_endian_" : ""); emit(1 + depth, "if(tlen < 0) return tlen; else pos += tlen;"); emit(1 + depth, "if(__elem_len > maxlen - pos) return -1;"); emitStart(1 + depth, "this->%s", mn); for(int i = 0; i < depth; i++) emitContinue("[a%d]", i); emitEnd(".assign(((const char*)buf) + offset + pos, __elem_len - 1);"); emit(1 + depth, "pos += __elem_len;"); } else { emitStart(1 + depth, "tlen = this->%s", mn); for(int i = 0; i < depth; i++) emitContinue("[a%d]", i); emitEnd("._decodeNoHash(buf, offset + pos, maxlen - pos);"); emit(1 + depth, "if(tlen < 0) return tlen; else pos += tlen;"); } } else { auto& dim = lm.dimensions[depth]; if(!lm.isConstantSizeArray()) { emitStart(1+depth, "this->%s", mn); for(int i = 0; i < depth; i++) { emitContinue("[a%d]", i); } emitEnd(".resize(%s);", dimSizeAccessor(dim.size).c_str()); } emit(1+depth, "for (int a%d = 0; a%d < %s; a%d++) {", depth, depth, dimSizeAccessor(dim.size).c_str(), depth); _decodeRecursive(lm, depth+1); emit(1+depth, "}"); } }
void emitHeaderStart() { const char *tn = ls.structname.fullname.c_str(); const char *sn = ls.structname.shortname.c_str(); string tnDots = dotsToUnderscores(ls.structname.fullname); const char *tn_ = tnDots.c_str(); emitAutoGeneratedWarning(); emit(0, "#include <zcm/zcm_coretypes.h>"); emit(0, ""); emit(0, "#ifndef __%s_hpp__", tn_); emit(0, "#define __%s_hpp__", tn_); emit(0, ""); // do we need to #include <vector> and/or <string>? bool emitIncludeVector = false; bool emitIncludeString = false; for (auto& lm : ls.members) { if (!emitIncludeVector && lm.dimensions.size() != 0 && !lm.isConstantSizeArray()) { emit(0, "#include <vector>"); emitIncludeVector = true; } if (!emitIncludeString && lm.type.fullname == "string") { emit(0, "#include <string>"); emitIncludeString = true; } } // include header files for other ZCM types for (auto& lm : ls.members) { auto& mtn = lm.type.fullname; if (!ZCMGen::isPrimitiveType(mtn) && mtn != tn) { emit(0, "#include \"%s%s%s.hpp\"", zcm.gopt->getString("cpp-include").c_str(), zcm.gopt->getString("cpp-include").size()>0 ? "/":"", dotsToSlashes(mtn).c_str()); } } emit(0, "\n"); emitPackageNamespaceStart(); // define the class emitComment(0, ls.comment); emit(0, "class %s", sn); emit(0, "{"); // data members if(ls.members.size() > 0) { emit(1, "public:"); for (auto& lm : ls.members) { auto& mtn = lm.type.fullname; emitComment(2, lm.comment); string mappedTypename = mapTypeName(mtn); int ndim = (int)lm.dimensions.size(); if (ndim == 0) { emit(2, "%-10s %s;", mappedTypename.c_str(), lm.membername.c_str()); } else { if (lm.isConstantSizeArray()) { emitStart(2, "%-10s %s", mappedTypename.c_str(), lm.membername.c_str()); for (auto& ld : lm.dimensions) emitContinue("[%s]", ld.size.c_str()); emitEnd(";"); } else { emitStart(2, ""); for (int d = 0; d < ndim; d++) emitContinue("std::vector< "); emitContinue("%s", mappedTypename.c_str()); for (int d = 0; d < ndim; d++) emitContinue(" >"); emitEnd(" %s;", lm.membername.c_str()); } } emit(0, ""); } } // constants if (ls.constants.size() > 0) { emit(1, "public:"); emit(2, "#if __cplusplus > 199711L /* if c++11 */"); for (auto& lc : ls.constants) { assert(ZCMGen::isLegalConstType(lc.type)); emitComment(2, lc.comment); string mt = mapTypeName(lc.type); const char *suffix = lc.type == "int64_t" ? "LL" : ""; emit(2, "static constexpr %-8s %s = %s%s;", mt.c_str(), lc.membername.c_str(), lc.valstr.c_str(), suffix); } emit(2, "#else"); for (auto& lc : ls.constants) { assert(ZCMGen::isLegalConstType(lc.type)); string mt = mapTypeName(lc.type); const char *suffix = lc.type == "int64_t" ? "LL" : ""; emit(2, "static const %-8s %s = %s%s;", mt.c_str(), lc.membername.c_str(), lc.valstr.c_str(), suffix); } emit(2, "#endif"); emit(0, ""); } emit(1, "public:"); emit(2, "/**"); emit(2, " * Destructs a message properly if anything inherits from it"); emit(2, "*/"); emit(2, "virtual ~%s() {}", ls.structname.shortname.c_str()); emit(0, ""); emit(2, "/**"); emit(2, " * Encode a message into binary form."); emit(2, " *"); emit(2, " * @param buf The output buffer."); emit(2, " * @param offset Encoding starts at thie byte offset into @p buf."); emit(2, " * @param maxlen Maximum number of bytes to write. This should generally be"); emit(2, " * equal to getEncodedSize()."); emit(2, " * @return The number of bytes encoded, or <0 on error."); emit(2, " */"); emit(2, "inline int encode(void *buf, int offset, int maxlen) const;"); emit(0, ""); emit(2, "/**"); emit(2, " * Check how many bytes are required to encode this message."); emit(2, " */"); emit(2, "inline int getEncodedSize() const;"); emit(0, ""); emit(2, "/**"); emit(2, " * Decode a message from binary form into this instance."); emit(2, " *"); emit(2, " * @param buf The buffer containing the encoded message."); emit(2, " * @param offset The byte offset into @p buf where the encoded message starts."); emit(2, " * @param maxlen The maximum number of bytes to reqad while decoding."); emit(2, " * @return The number of bytes decoded, or <0 if an error occured."); emit(2, " */"); emit(2, "inline int decode(const void *buf, int offset, int maxlen);"); emit(0, ""); emit(2, "/**"); emit(2, " * Retrieve the 64-bit fingerprint identifying the structure of the message."); emit(2, " * Note that the fingerprint is the same for all instances of the same"); emit(2, " * message type, and is a fingerprint on the message type definition, not on"); emit(2, " * the message contents."); emit(2, " */"); emit(2, "inline static int64_t getHash();"); emit(0, ""); emit(2, "/**"); emit(2, " * Returns \"%s\"", ls.structname.shortname.c_str()); emit(2, " */"); emit(2, "inline static const char* getTypeName();"); emit(0, ""); emit(2, "// ZCM support functions. Users should not call these"); emit(2, "inline int _encodeNoHash(void *buf, int offset, int maxlen) const;"); emit(2, "inline int _getEncodedSizeNoHash() const;"); emit(2, "inline int _decodeNoHash(const void *buf, int offset, int maxlen);"); emit(2, "inline static uint64_t _computeHash(const __zcm_hash_ptr *p);"); emit(0, "};"); emit(0, ""); }