void emit_constructor(FILE *fl) { def->emit_template_long(fl); fprintf(fl,"%s",def->name.c_str()); def->emit_template_short(fl); fprintf(fl," *"/*,def->name.c_str()*/); // def->emit_template_short(fl); fprintf(fl,"ctor_%s(",name.c_str()); for(int i=0;i<params.size();++i) { if(types.count(params_canonical[i])) { fprintf(fl,"_alg_ptr<%s > const &pp%d",params[i].c_str(),i); } else fprintf(fl,"%s pp%d",params[i].c_str(),i); if(i!=params.size()-1) fprintf(fl,","); } fprintf(fl,") {\n"); fprintf(fl,"%s",def->name.c_str()); def->emit_template_short(fl); fprintf(fl,"*r=new %s",def->name.c_str()); def->emit_template_short(fl); fprintf(fl,";\nr->_discr=%s;\n",name.c_str()); for(int i=0;i<params.size();++i) { fprintf(fl,"r->s%s.p%d=pp%d;\n",name.c_str(),i,i); if(types.count(params_canonical[i])) fprintf(fl,"r->s%s.p%d._alg_ref();\n",name.c_str(),i); } fprintf(fl,"return r;\n}\n"); }
// end int main(int argc, char* argv[]) { CType obj; int n; cin >> n; while (n) { obj.setvalue(n); cout << obj++ << " " << obj << endl; cin >> n; } return 0; }
// --------------------------------------------------------------------------- void CGeorgesImpl::MakeTyp( const std::string& filename, TType type, TUI ui, const std::string& _min, const std::string& _max, const std::string& _default, const std::vector< std::pair< std::string, std::string > >* const _pvpredef ) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); // Create a type CType t; t.Type = (CType::TType)type; t.UIType = (CType::TUI)ui; t.Min= _min; t.Max = _max; t.Default = _default; if (_pvpredef) { t.Definitions.resize (_pvpredef->size ()); uint i; for (i=0; i<_pvpredef->size (); i++) { t.Definitions[i].Label = (*_pvpredef)[i].first; t.Definitions[i].Value = (*_pvpredef)[i].second; } } // Save the type COFile output; if (output.open (filename)) { try { // XML stream COXml outputXml; outputXml.init (&output); // Write t.write (outputXml.getDocument ()); } catch (Exception &e) { nlwarning ("Error during writing file '%s' : ", filename.c_str (), e.what ()); } } else { nlwarning ("Can't open the file %s for writing", filename.c_str ()); } }
CActionString::CActionString (IAction::TTypeAction type, const char *newValue, CGeorgesEditDoc &doc, const char *formName, const char *userData, uint selId, uint slot) : IAction (type, selId, slot) { // Set the new value _NewValue = newValue; _FormName = formName; _Log[1] = newValue; _UserData = userData; // Backup old value switch (_Type) { case TypeType: { CType *type = doc.getTypePtr (); _OldValue = toString ((int)(type->Type)); setLabel ("Type Type", doc); _Log[1] = type->getTypeName ((UType::TType)atoi (newValue)); } break; case TypeUI: { CType *type = doc.getTypePtr (); _OldValue = toString ((int)(type->UIType)); setLabel ("Type UI", doc); _Log[1] = type->getUIName ((CType::TUI)atoi (newValue)); } break; case TypeDefault: { CType *type = doc.getTypePtr (); _OldValue = type->Default; setLabel ("Type Default", doc); } break; case TypeMin: { CType *type = doc.getTypePtr (); _OldValue = type->Min; setLabel ("Type Min", doc); } break; case TypeMax: { CType *type = doc.getTypePtr (); _OldValue = type->Max; setLabel ("Type Max", doc); } break; case TypeIncrement: { CType *type = doc.getTypePtr (); _OldValue = type->Increment; setLabel ("Type Increment", doc); } break; case FormTypeValue: case FormValue: { // Form const NLGEORGES::CForm &form = *(doc.getFormPtr ()); nlverify (doc.getRootNode (_Slot)->getValueByName (_OldValue, formName, UFormElm::NoEval, NULL)); setLabel (formName, doc); } break; case HeaderVersion: { CFileHeader *header = doc.getHeaderPtr (); char versionText[512]; smprintf (versionText, 512, "Version %d.%d", header->MajorVersion, header->MinorVersion); _OldValue = versionText; setLabel ("Header Version", doc); } break; case HeaderState: { CFileHeader *header = doc.getHeaderPtr (); _OldValue = toString ((int)(header->State)).c_str (); setLabel ("Header State", doc); } break; case HeaderComments: { _OldValue = doc.getHeaderPtr ()->Comments; setLabel ("Header Comments", doc); } break; case FormArrayRename: { setLabel ((formName+string (" Renamed")).c_str (), doc); int idInParent = atoi (_UserData.c_str ()); // Get the parent node const CFormDfn *parentDfn; uint indexDfn; const CFormDfn *nodeDfn; const CType *nodeType; CFormElm *node; UFormDfn::TEntryType type; bool array; bool vdfnArray; CForm *form=doc.getFormPtr (); CFormElm *elm = doc.getRootNode (slot); nlverify ( elm->getNodeByName (_FormName.c_str (), &parentDfn, indexDfn, &nodeDfn, &nodeType, &node, type, array, vdfnArray, true, NLGEORGES_FIRST_ROUND) ); if (node) { CFormElmArray* array = safe_cast<CFormElmArray*> (node->getParent ()); _OldValue = array->Elements[idInParent].Name; } } break; case FormArrayInsert: { // do nothing setLabel ("Array Insert", doc); } break; default: nlstop; } }
inline bool CObject::IsObjectType (const CType& t) const { return GetType().Get() == t.Get(); }
inline bool operator ==(const CType& l, const CType& r) { return l.Get() == r.Get(); }
CType& CType::operator++(int){ CType* temp = new CType(); temp->setvalue(num); num = num * num; return *temp; }
/* * Init database * \param xmlStream is the xml description of the database */ bool CDatabase::init() { PDS_DEBUG("init()"); // clear all before doing anything clear(); const CDatabaseNode& db = _Description.getDatabaseNode(); _State.Name = db.Name; uint i; for (i=0; i<db.Types.size(); ++i) { CType* type = new CType; if (!type->init(this, db.Types[i])) { PDS_WARNING("init(): failed to init type '%d'", i); return false; } if (type->getId() != i) { PDS_WARNING("init(): failed to init type '%d'", i); return false; } _Types.push_back(type); } for (i=0; i<db.Tables.size(); ++i) { CTable* table = new CTable(); if (!table->init(this, db.Tables[i]) || table->getId() != i) { PDS_WARNING("init(): failed to init table '%d'", i); return false; } _Tables.push_back(table); } for (i=0; i<_Tables.size(); ++i) { CTable* table = _Tables[i]; if (!table->buildColumns()) { PDS_WARNING("init(): failed to build table '%d' columns", i); return false; } } for (i=0; i<_Tables.size(); ++i) { _Tables[i]->postInit(); } _Init = true; if (!notifyNewReference(false)) { _Init = false; return false; } // save description in log dir std::string logDir = RY_PDS::CPDSLib::getLogDirectory(_State.Id); if (!CFile::isExists(logDir) || !CFile::isDirectory(logDir)) { if (!CFile::createDirectoryTree(logDir)) { PDS_WARNING("init(): failed to create log root directory '%s'", logDir.c_str()); } if (!CFile::setRWAccess(logDir)) { PDS_WARNING("init(): failed, can't set RW access to directory '%s'", logDir.c_str()); } } // CTimestamp initDate; // initDate.setToCurrent(); // _Description.saveDescription(logDir + initDate.toString() + ".description"); PDS_DEBUG("init() successful"); return true; }