void doCreate(const char *partname, const char *xml, unsigned updateFlags, StringArray &filesNotFound) { createPart(partname, xml); if (pmExisting) { if (!checkFlag(PKGADD_MAP_REPLACE)) throw MakeStringException(PKG_NAME_EXISTS, "PackageMap %s already exists, either delete it or specify overwrite", pmid.str()); } cloneDfsInfo(updateFlags, filesNotFound); if (pmExisting) packageMaps->removeTree(pmExisting); Owned<IPropertyTree> pmTree = createPTree("PackageMap", ipt_ordered); pmTree->setProp("@id", pmid); pmTree->setPropBool("@multipart", true); pmTree->addPropTree("Part", pmPart.getClear()); packageMaps->addPropTree("PackageMap", pmTree.getClear()); VStringBuffer xpath("PackageMap[@id='%s'][@querySet='%s']", pmid.str(), target.get()); Owned<IPropertyTree> pkgSet = getPkgSetRegistry(process, false); IPropertyTree *psEntry = pkgSet->queryPropTree(xpath); if (!psEntry) { psEntry = pkgSet->addPropTree("PackageMap", createPTree("PackageMap")); psEntry->setProp("@id", pmid); psEntry->setProp("@querySet", target); } makePackageActive(pkgSet, psEntry, target, checkFlag(PKGADD_MAP_ACTIVATE)); }
bool File::directoryCreate( Path const & p_path, FlagCombination< CreateMode > const & p_flags ) { Path path = p_path.getPath(); if ( !path.empty() && !directoryExists( path ) ) { directoryCreate( path, p_flags ); } mode_t mode = 0; if ( checkFlag( p_flags, CreateMode::eUserRead ) ) { mode |= S_IRUSR; } if ( checkFlag( p_flags, CreateMode::eUserWrite ) ) { mode |= S_IWUSR; } if ( checkFlag( p_flags, CreateMode::eUserExec ) ) { mode |= S_IXUSR; } if ( checkFlag( p_flags, CreateMode::eGroupRead ) ) { mode |= S_IRGRP; } if ( checkFlag( p_flags, CreateMode::eGroupWrite ) ) { mode |= S_IWGRP; } if ( checkFlag( p_flags, CreateMode::eGroupExec ) ) { mode |= S_IXGRP; } if ( checkFlag( p_flags, CreateMode::eOthersRead ) ) { mode |= S_IROTH; } if ( checkFlag( p_flags, CreateMode::eOthersWrite ) ) { mode |= S_IWOTH; } if ( checkFlag( p_flags, CreateMode::eOthersExec ) ) { mode |= S_IXOTH; } return mkdir( string::stringCast< char >( p_path ).c_str(), mode ) == 0; }
float Object::_evalOpacity( Material* mat ) { if ( checkFlag( NODE_USE_MAT_OPACITY ) && mat ) return mat->getOpacity(); return mOpacity; }
bool SMDTable::open( FILE* file,int offset,unsigned short pageSize/*=4096*/,bool exists /*= true*/ ) { this->file = file; this->offset = offset; if(exists && !checkFlag()) { return false; } if(!exists) { saveFlag(pageSize); } if(pageMgr != NULL) delete pageMgr; pageMgr = new SMDPageManagement(this,exists,pageSize); if(pageMgr == NULL) { return false; } // 初始化各个段结构 segMeta = new SMDMetaSegment(pageMgr); segTable = new SMDTableSegment(pageMgr); segData = new SMDDataSegment(segTable,pageMgr); segIndex = new SMDIndexSegment(pageMgr); return true; }
void RenderWidget::showEvent( QShowEvent* /*event*/ ) { if (!checkFlag(Window::eFlags_IsVisible)) { raiseFlag(Window::eFlags_IsVisible); Shown(); } }
void RenderWidget::hideEvent( QHideEvent* /*event*/ ) { if (checkFlag(Window::eFlags_IsVisible)) { clearFlag(Window::eFlags_IsVisible); Hidden(); } }
inline void doRenderNodeNoPass( SkinningRenderNode & node ) { if ( !checkFlag( node.m_pipeline.getFlags().m_programFlags, ProgramFlag::eInstantiation ) ) { node.m_skinningUbo.update( node.m_skeleton ); } doRenderObjectNode( node ); }
void Packet::get(char * value, uint16 size) { if( !checkFlag(STRING_FLAG) ) return; uint16 svalue = 0; read(svalue); int s = svalue < size ? svalue : size; read(value, s); }
Vec2i const& TUICore<T>::getWorldPos() { if ( !checkFlag( UF_WORLD_POS_VAILD ) ) { mCacheWorldPos = getPos(); if ( mParent && mParent != getManager()->getRoot() ) mCacheWorldPos += mParent->getWorldPos(); _addFlag( UF_WORLD_POS_VAILD ); } return mCacheWorldPos; }
void createPart(const char *partname, const char *xml) { if (!partname || !*partname) throw MakeStringExceptionDirect(PKG_INFO_NOT_DEFINED, "No PackageMap Part name provided"); if (!xml || !*xml) throw MakeStringExceptionDirect(PKG_INFO_NOT_DEFINED, "No PackageMap content provided"); pmPart.setown(createPTreeFromXMLString(xml)); if (!pmPart) throw MakeStringExceptionDirect(PKG_INFO_NOT_DEFINED, "Invalid PackageMap content"); pmPart->addProp("@id", partname); StringBuffer lcPmid(pmid); pmid = lcPmid.toLowerCase().str(); fixPackageMapFileIds(pmPart, checkFlag(PKGADD_PRELOAD_ALL)); }
void createPart(const char *partname, const char *xml) { if (!partname || !*partname) throw MakeStringExceptionDirect(PKG_INFO_NOT_DEFINED, "No PackageMap Part name provided"); if (!xml || !*xml) throw MakeStringExceptionDirect(PKG_INFO_NOT_DEFINED, "No PackageMap content provided"); pmPart.setown(createPTreeFromXMLString(xml)); if (!pmPart) throw MakeStringExceptionDirect(PKG_INFO_NOT_DEFINED, "Invalid PackageMap content"); pmPart->addProp("@id", partname); StringBuffer lcPmid(pmid); pmid = lcPmid.toLowerCase().str(); Owned<IPropertyTreeIterator> iter = pmPart->getElements("Package"); ForEach(*iter) { IPropertyTree &item = iter->query(); if (checkFlag(PKGADD_PRELOAD_ALL)) item.setPropBool("@preload", true); Owned<IPropertyTreeIterator> superFiles = item.getElements("SuperFile"); ForEach(*superFiles) { IPropertyTree &superFile = superFiles->query(); StringBuffer lc(superFile.queryProp("@id")); const char *id = lc.toLowerCase().str(); if (*id == '~') id++; superFile.setProp("@id", id); Owned<IPropertyTreeIterator> subFiles = superFile.getElements("SubFile"); ForEach(*subFiles) { IPropertyTree &subFile = subFiles->query(); id = subFile.queryProp("@value"); if (id && *id == '~') { StringAttr value(id+1); subFile.setProp("@value", value.get()); } } } } }
void addPart(const char *partname, const char *xml, unsigned updateFlags, StringArray &filesNotFound) { init(); if (!pmExisting) { doCreate(partname, xml, updateFlags, filesNotFound); return; } createPart(partname, xml); VStringBuffer xpath("Part[@id='%s']", partname); IPropertyTree *existingPart = pmExisting->queryPropTree(xpath); if (existingPart && !checkFlag(PKGADD_SEG_REPLACE)) throw MakeStringException(PKG_NAME_EXISTS, "Package Part %s already exists, remove, or specify 'delete previous'", partname); cloneDfsInfo(updateFlags, filesNotFound); if (existingPart) pmExisting->removeTree(existingPart); pmExisting->addPropTree("Part", pmPart.getClear()); }
void Packet::get(int64 & value) { if( checkFlag(INT64_FLAG) ) read(value); }
void cloneDfsInfo(unsigned updateFlags, StringArray &filesNotFound) { cloneFileInfoToDali(updateFlags, filesNotFound, pmPart, daliIP, ensureClusterInfo(), srcCluster, prefix, userdesc, checkFlag(PKGADD_ALLOW_FOREIGN)); }
/* Processes the command line arguments and calls the appropriate function from * lzw.h */ int main(int argc, char** argv) { MODE mode; /* indicates whether lzw is called as encode or decode */ // check argv[0] to see if it's encode or decode if(argc == 0 || (mode = encodeOrDecode(argv[0])) == INVALID) { argsError(); return INVALID_ARGS; } else if(mode == DECODE) { if(argc > 1) // decode cannot have additional args { argsError(); return INVALID_ARGS; } else { if(!decode()) { fprintf(stderr, "Error on decode; invalid encoded stream\n"); return FAILED_DECODE; } } } else // mode == ENCODE { long maxBits = 0; // value of -m argument, or 0 if there's no -m long window = 0; // value of -p argument, or 0 if there's no -p bool eFlag = false; // true if -e flag has been seen // iterate over args for(unsigned int i = 1; i < argc; i++) { FLAG argType = checkFlag(argv[i]); switch(argType) { case M: i++; if(i >= argc || // there is no following number arg (maxBits = checkNumArg(argv[i])) <= 0) { argsError(); return 1; } else { // maxBits is a positive int; now set to correct value // if out of range if(maxBits <= 8 || maxBits > 24) { maxBits = 12; } } break; case P: i++; if(i >= argc || // there is no following number arg (window = checkNumArg(argv[i])) <= 0) { argsError(); return 1; } break; case E: eFlag = true; break; default: argsError(); return 1; } } if(!maxBits) // if maxBits wasn't set, default to 12 { maxBits = 12; } encode(maxBits, window, eFlag); } return SUCCESS; }
Expect & operator++() { _val++; checkFlag(); return *this; }
void Packet::get(int8 & value) { if( checkFlag(BYTE_FLAG) ) read(value); }
void Packet::get(uint16 & value) { if( checkFlag(WORD_FLAG) ) read(value); }
bool checkFlag(T f, Args ... rest) const { if (sizeof ...(rest)) return FLAG.test(f) && checkFlag (rest...); return FLAG.test (f); }
int MailData::parse(const char *msg, size_t /* len */) { int ret = 0; unsigned int start = 0, end = 0; isMailPartial = false; // Get attributes read = checkFlag(msg, EMAIL_READ); forwarded = checkFlag(msg, EMAIL_FORW); replied = checkFlag(msg, EMAIL_REPL); deleted = checkFlag(msg, EMAIL_DELE); flagged = checkFlag(msg, EMAIL_FLAG); if( XMLProcessor::getElementContent (msg, EMAIL_TREC, NULL, &start, &end) ) { received = StringBuffer(msg+start, end-start); } else received = ""; if( XMLProcessor::getElementContent (msg, EMAIL_TCRE, NULL, &start, &end) ) { created = StringBuffer(msg+start, end-start); } else created = ""; if( XMLProcessor::getElementContent (msg, EMAIL_TMOD, NULL, &start, &end) ) { modified = StringBuffer(msg+start, end-start); } else modified = ""; // Get content StringBuffer itemtmp(msg); start = itemtmp.find(EMAIL_ITEM_START); end = itemtmp.rfind(EMAIL_ITEM_END); if (start != StringBuffer::npos && end != StringBuffer::npos) { totalEmailSize = itemtmp.length(); // the size of the current piece of mail itemtmp = NULL; //if( XMLProcessor::getElementContent(msg, EMAIL_ITEM, NULL, &start, &end) ) { StringBuffer item(msg+start, end-start); unsigned int startAttr=0, endAttr=0; //currently emailitem is not escaped so false!! if(XMLProcessor::getElementAttributes(msg, EMAIL_ITEM, &startAttr, &endAttr, false)) { StringBuffer attrlist(msg+startAttr, endAttr-startAttr); if(attrlist.ifind("quoted-printable") != StringBuffer::npos) { char *decoded = qp_decode(item); item = decoded; delete [] decoded; } } // item must start with CDATA size_t item_start = item.find("![CDATA"); if(item_start > 50){ // it could be <emailitem ENC="QUOTED-PRINTABLE"><![CDATA[ LOG.error("MailData: can't find inner CDATA section."); return -1; } size_t item_end = item.rfind("]]>"); // In emailitem the last > close the CDATA of emailitem tag and is escaped, so it is needed // to be found the follow. Usually the first is skipped // if(item.length() - item_end > 10){ item_end = item.rfind("]]>"); if(item.length() - item_end > 10){ LOG.error("MailData: can't find CDATA end tag."); return -2; } } // okay, move the start pointer to the end of item_start += strlen("![CDATA["); ret=emailItem.parse( item.c_str()+item_start, item_end - item_start ); } else { // LOG.info("MailData: no <emailitem> tag."); // It is not an error, just log it for info. } /* char tmpExt[] = "<Ext><XNam>x-funambol-body</XNam><XVal>15000</XVal></Ext> \ <Ext><XNam>x-funambol-attach-n</XNam><XVal>1</XVal></Ext> \ <Ext><XNam>x-funambol-attach</XNam><XVal>att1.txt</XVal><XVal>10000</XVal></Ext>"; */ //char tmpExt[] = ""; // find the Ext stuffs if (end != StringBuffer::npos) { unsigned int pos = end; unsigned int previous = end; start = 0, end = 0; char* ext = NULL; // for try //pos = 0; //while( (ext = XMLProcessor::copyElementContent(&tmpExt[pos], "Ext", &pos)) ) { // for try while( (ext = XMLProcessor::copyElementContent(&msg[pos], "Ext", &pos)) ) { char* xnam = XMLProcessor::copyElementContent(ext, "XNam", 0); if (!xnam) break; if (strcmp(xnam, "x-funambol-body") == 0) { char* val = XMLProcessor::copyElementContent(ext, "XVal", 0); if (val) { setRemainingBodySize(atol(val)); totalEmailSize += atol(val); delete [] val; val = NULL; isMailPartial = true; } } else if (strcmp(xnam, "x-funambol-attach-n") == 0) { char* val = XMLProcessor::copyElementContent(ext, "XVal", 0); if (val) { setRemainingAttachNumber(atol(val)); delete [] val; val = NULL; isMailPartial = true; } } else if (strcmp(xnam, "x-funambol-attach") == 0) { if (!remainingAttachments) { remainingAttachments = new ArrayList(); } extMailData = new ExtMailData(); unsigned int from = 0; int prev = 0; char* val = XMLProcessor::copyElementContent(ext, "XVal", &from); if (val) { extMailData->attachName = stringdup(MailMessage::decodeHeader(val).c_str()); delete [] val; val = NULL; } prev = from; val = XMLProcessor::copyElementContent(&ext[from], "XVal", &from); if (val) { extMailData->attachSize = atol(val); totalEmailSize += atol(val); delete [] val; val = NULL; } from += prev; prev = from; val = XMLProcessor::copyElementContent(&ext[from], "XVal", &from); if (val) { extMailData->attachMime = stringdup(MailMessage::decodeHeader(val).c_str()); delete [] val; val = NULL; } from += prev; prev = from; val = XMLProcessor::copyElementContent(&ext[from], "XVal", &from); if (val) { extMailData->attachURL = stringdup(MailMessage::decodeHeader(val).c_str()); delete [] val; val = NULL; } if (extMailData->attachName && extMailData->attachSize != 0) { remainingAttachments->add(*extMailData); isMailPartial = true; } else { setRemainingAttachNumber(getRemainingAttachNumber() == 0 ? 0 : (getRemainingAttachNumber() - 1)); } delete extMailData; extMailData = NULL; } pos += previous; previous = pos; if (xnam) { delete [] xnam; xnam = NULL; } if (ext) { delete [] ext; ext = NULL; } } } return ret; }
inline void doBindPass( SceneNode & sceneNode , PassRenderNode & node , Scene & scene , RenderPipeline & pipeline , ShadowMapLightTypeArray & shadowMaps , ModelUbo & model , EnvironmentMap *& envMap ) { node.m_pass.bindTextures(); uint32_t index = pipeline.getTexturesCount() + MinTextureIndex; if ( checkFlag( pipeline.getFlags().m_programFlags, ProgramFlag::eLighting ) ) { doFillShaderShadowMaps( pipeline, shadowMaps, index ); } if ( ( checkFlag( pipeline.getFlags().m_passFlags, PassFlag::ePbrMetallicRoughness ) || checkFlag( pipeline.getFlags().m_passFlags, PassFlag::ePbrSpecularGlossiness ) ) && checkFlag( pipeline.getFlags().m_programFlags, ProgramFlag::eLighting ) ) { index = doFillShaderPbrMaps( pipeline , scene , sceneNode , index ); } for ( auto pair : node.m_textures ) { auto texture = pair.first; auto & variable = pair.second; if ( texture ) { variable.get().setValue( texture ); } } for ( auto & array : shadowMaps ) { for ( auto & shadowMap : array ) { shadowMap.get().getTexture().bind(); } } if ( node.m_pass.hasEnvironmentMapping() ) { envMap = &scene.getEnvironmentMap( sceneNode ); if ( checkFlag( pipeline.getFlags().m_programFlags, ProgramFlag::eLighting ) ) { pipeline.getEnvironmentMapVariable().setValue( index ); envMap->getTexture().setIndex( index ); envMap->getTexture().bind(); } else { model.setEnvMapIndex( envMap->getIndex() ); } } else { model.setEnvMapIndex( 0 ); envMap = nullptr; } }
int main(int numargs, char *args[]){ //should have either 4, 5, 6, or 7 arguments //if 7, [1] must be -r, [2,3,4] must be ints, initial and goal are letters //if 6, must not include -r, include all else //if 5 must include -r and not height OR width //if 4, must have int for maxlength and letters for other, and nothing else //height and width are ints between 2 and 5 (Default is 3) //maxlength is non-negative int (can be 0) //INITIAL and GOAL have the necessary number of letters for the size of the tray //letters between only A and L (duplicates ok) int width = 3; //width of the tray, default is 3 int height = 3; //height of the tray, default is 3 int maxlength = -1; //maxlength of the pattern int tilelen; //number of tiles char *temp; bool flag; //true is -r is specified bool used; char *initial; //initial position char *goal; //goal position //if all the command-line args follow the rules for 4 args if((numargs == 4) && checkNum(args[1]) && checkTiles(args[2], args[3])){ maxlength = (int)strtol(args[1], &temp, 10); tilelen = strlen(args[2]); flag = false; //no flag present initial = args[2]; goal = args[3]; } //if all the command-line args follow the rules for 5 args else if((numargs == 5) && checkFlag(args[1]) && checkNum(args[2]) && checkTiles(args[3], args[4])){ maxlength = (int)strtol(args[2], &temp, 10); tilelen = strlen(args[3]); flag = true; //flag present initial = args[3]; goal = args[4]; } //if all the command-line args follow the rules for 6 args else if((numargs == 6) && checkNum(args[1]) && checkNum(args[2]) && checkNum(args[3]) && checkTiles(args[4], args[5])){ height = (int)strtol(args[1], &temp, 10); width = (int)strtol(args[2], &temp, 10); maxlength = (int)strtol(args[3], &temp, 10); tilelen = strlen(args[4]); flag = false; //no flag present initial = args[4]; goal = args[5]; } //if all the command-line args follow the rules for 7 args else if((numargs == 7) && checkFlag(args[1]) && checkNum(args[2]) && checkNum(args[3]) && checkNum(args[4]) && checkTiles(args[5], args[6])){ height = (int)strtol(args[2], &temp, 10); width = (int)strtol(args[3], &temp, 10); maxlength = (int)strtol(args[4], &temp, 10); tilelen = strlen(args[5]); flag = true; //flag present initial = args[5]; goal = args[6]; } else{//invalid command line args fprintf(stderr, "Invalid command line arguments\n"); exit(1); } if((height >= 2) && (height <= 5) && (width >= 2) && (width <= 5) && (tilelen == height*width)){} else{//if the height and width aren't right, then quit fprintf(stderr, "Invalid command line arguments\n"); exit(1); } Stack q1; //create the two stacks for the queue Stack q2; createS(&q1); createS(&q2); char *nextStr; //holds what is popped off queue 'P' int nextLen; //holds the length of P Trie root; //root of the trie dictionary root.len = -1; root.from = NULL; for(int k = 0; k < 12; k++) root.children[k] = NULL; insert(&root, goal, NULL, 0); //insert root in queue & dictionary pushS(&q1, goal); if(!(strcmp(goal, initial))){ //if goal is initial printf("%s\n", initial); destroyS(&q1); destroyS(&q2); return 0; } while(!(isEmptyS(&q1) && isEmptyS(&q2))){ //while queue not empty popQ(&q1, &q2, &nextStr); nextLen = lenInTrie(&root, nextStr); used = false; if(nextLen < maxlength){ //generate all the possible tiles for(int c = 0; c < width; c++){ //for all column shifts if(flag){//-r, then do it for all possible shifts for(int sh = 1; sh < width; sh++){ char *nextTiles = shiftC(nextStr, height, width, c, height - sh); //next tile pattern generated by a shift if(!strcmp(nextTiles, initial)){ insert(&root, nextTiles, nextStr, nextLen + 1); printSteps(root, nextTiles); destroyS(&q1); destroyS(&q2); return 0; } if(insert(&root, nextTiles, nextStr, nextLen + 1)){ pushS(&q1, nextTiles); //add it to the queue and dictionary used = true; } else free(nextTiles); } } else{//else do it for shift is one step only char *nextTiles = shiftC(nextStr, height, width, c, height - 1); //next tile pattern generated by a shift if(!strcmp(nextTiles, initial)){ insert(&root, nextTiles, nextStr, nextLen + 1); printSteps(root, nextTiles); destroyS(&q1); destroyS(&q2); return 0; } if(insert(&root, nextTiles, nextStr, nextLen + 1)){ pushS(&q1, nextTiles); //add it to the queue and dictionary used = true; } else free(nextTiles); } } for(int r = 0; r < height; r++){//for all possible row shifts if(flag){//-r, then do it for all possible shifts for(int sh = 1; sh < height; sh++){ char *nextTiles = shiftR(nextStr, height, width, r, width - sh); //next tile pattern generated by a shift if(!strcmp(nextTiles, initial)){ insert(&root, nextTiles, nextStr, nextLen + 1); printSteps(root, nextTiles); destroyS(&q1); destroyS(&q2); return 0; } if(insert(&root, nextTiles, nextStr, nextLen + 1)){ pushS(&q1, nextTiles); //add it to the queue and dictionary used = true; } else free(nextTiles); } } else{//else do it for shift is one step only char *nextTiles = shiftR(nextStr, height, width, r, width - 1); //next tile pattern generated by a shift if(!strcmp(nextTiles, initial)){ insert(&root, nextTiles, nextStr, nextLen + 1); printSteps(root, nextTiles); destroyS(&q1); destroyS(&q2); return 0; } if(insert(&root, nextTiles, nextStr, nextLen + 1)){ pushS(&q1, nextTiles); //add it to the queue and dictionary used = true; } else free(nextTiles); } } } if(!used) free(nextStr); }//end of while queue is not empty destroyS(&q1); destroyS(&q2); return 0; }
Expect & operator--() { _val--; checkFlag(); return *this; }
bool RenderWidget::isOpen() const { return QGLWidget::isVisible() && checkFlag(Window::eFlags_IsVisible); }