void OMFile::initialize(void) { TRACE("OMFile::initialize"); PRECONDITION("No valid factory", _factory == 0); PRECONDITION("No valid default encoding map", _defaultEncodings == 0); _factory = new OMFile::FactorySet(); _defaultEncodings = new OMFile::DefaultEncodings; POSTCONDITION("Valid factory", _factory ); POSTCONDITION("Valid default encoding map", _defaultEncodings ); }
bool OMDataStreamProperty::hasStreamAccess(void) const { TRACE("OMDataStreamProperty::hasStreamAccess"); bool result; if (_streamAccess != 0) { result = true; } else { result = false; } POSTCONDITION("Consistent result", IMPLIES(_streamAccess == 0, !result)); POSTCONDITION("Consistent result", IMPLIES(_streamAccess != 0, result)); return result; }
/** * \brief Constructeur de BorneFontaine * \param[in] p_idBorne int Le numéro de la borne. Not-Null * \param[in] p_direction string Le côté du centre de chaussé ou l'intersection dans le cas t'un terre-plein. * \param[in] p_nomTopographique string Le nom topographique(générique,liaison,spécifique,direction) du centre de la chaussée. * \param[in] p_longitude double La longitude de la borne * \param[in] p_latitude double La latitude de la borne * \param[in] p_ville string Le nom de la ville Il doit être non vide * \param[in] p_arrondissement string L'arrondissement Il doit être non vide si la ville est Quebec * \pre p_direction doit être un point cardinal valide [Nord,Sud,Est,Ouest,"",null] (Par héritances) * \pre p_ville non vide * \pre p_arrondissement non vide si p_ville = Quebec * \post vérification des attribut membre qu'ils contiennent tous des attributs valide * \return un objet BorneFontaine */ BorneFontaine::BorneFontaine(int p_idBorne, const std::string& p_direction, const std::string& p_nomTopographique, double p_longitude, double p_latitude, const std::string& p_ville, const std::string& p_arrondissement) :Borne(p_idBorne,p_direction,p_nomTopographique,p_longitude,p_latitude), m_ville(p_ville), m_arrondissement(p_arrondissement){ PRECONDITION(!p_ville.empty()); PRECONDITION(!(p_ville == "Quebec" && p_arrondissement.empty())); POSTCONDITION(!m_ville.empty()); POSTCONDITION(!(m_ville == "Quebec" && m_arrondissement.empty())); INVARIANTS(); }
/// Causes an invariant failure dependent on first argument value. /// One ignored argument is accepted to conform with the test.pl script, /// which would be the input source file for other cbmc driver programs. /// Returns 1 on unexpected arguments. int main(int argc, char** argv) { if(argc!=3) return 1; std::string arg=argv[1]; if(arg=="structured") INVARIANT_STRUCTURED(false, structured_error_testt, 1, "Structured error"); // NOLINT else if(arg=="string") INVARIANT(false, "Test invariant failure"); else if(arg=="precondition-structured") PRECONDITION_STRUCTURED(false, structured_error_testt, 1, "Structured error"); // NOLINT else if(arg=="precondition-string") PRECONDITION(false); else if(arg=="postcondition-structured") POSTCONDITION_STRUCTURED(false, structured_error_testt, 1, "Structured error"); // NOLINT else if(arg=="postcondition-string") POSTCONDITION(false); else if(arg=="check-return-structured") CHECK_RETURN_STRUCTURED(false, structured_error_testt, 1, "Structured error"); // NOLINT else if(arg=="check-return-string") CHECK_RETURN(false); else if(arg=="unreachable-structured") UNREACHABLE_STRUCTURED(structured_error_testt, 1, "Structured error"); // NOLINT else if(arg=="unreachable-string") UNREACHABLE; else if(arg=="data-invariant-structured") DATA_INVARIANT_STRUCTURED(false, structured_error_testt, 1, "Structured error"); // NOLINT else if(arg=="data-invariant-string") DATA_INVARIANT(false, "Test invariant failure"); else if(arg=="irep") INVARIANT_WITH_IREP(false, "error with irep", pointer_type(void_typet())); else return 1; }
const wchar_t* ImplAAFTypeDefExtEnum::elementName(OMUInt32 index) const { TRACE("ImplAAFTypeDefExtEnum::elementName"); PRECONDITION( "Valid index", index < elementCount() ); // Get the element names buffer and the number of characters in the buffer const wchar_t* namesBuffer = reinterpret_cast<const wchar_t*>(_ElementNames.bits()); const size_t namesBufferSize = _ElementNames.bitsSize() / sizeof(wchar_t); // Allocate an array that will contain the pointers to the element names const size_t nameCount = ImplAAFTypeDef::stringArrayStringCount( namesBuffer, namesBufferSize ); ASSERT( "Valid name count", nameCount == elementCount() ); const wchar_t** names = new const wchar_t*[ nameCount ]; // Get the pointers to the element names ImplAAFTypeDef::getStringArrayStrings( namesBuffer, namesBufferSize, names, nameCount ); // The reguested element name const wchar_t* result = names[index]; delete[] names; names = 0; POSTCONDITION( "Valid result", result != 0 ); return result; }
// @mfunc If <p propertyPath> is not already present then insert // it (by copying) into the table and return its tag, // otherwise just return its tag. Tags are allocated // sequentially. // @parm The property path to insert. // @rdesc The assigned index. OMPropertyTag OMPropertyTable::insert(const OMPropertyId* propertyPath) { TRACE("OMPropertyTable::insert"); PRECONDITION("Valid property path", validPropertyPath(propertyPath)); PRECONDITION("Room in table", count() < OMUINT16_MAX); OMPropertyTag result = nullOMPropertyTag; bool found = false; OMUInt16 elements = count(); for (OMUInt16 i = 0; i < elements; i++) { if (comparePropertyPath(_vector.valueAt(i), propertyPath) == 0) { result = i; found = true; break; } } if (!found) { _vector.append(savePropertyPath(propertyPath)); result = elements; } POSTCONDITION("Valid result", isValid(result)); return result; }
// @mfunc Set the value of this <c OMWeakObjectReference>. // The value is a pointer to the referenced <c OMStorable>. // @parm TBS // @parm A pointer to the new <c OMStorable>. // @rdesc A pointer to previous <c OMStorable>, if any. OMStorable* OMWeakObjectReference::setValue( const void* identification, const OMStorable* value) { TRACE("OMWeakObjectReference::setValue"); PRECONDITION("Valid container property", _property != 0); PRECONDITION("Valid identification", (_identification != 0) && (_identificationSize > 0)); PRECONDITION("Valid new identification", identification != 0); ASSERT("Valid identification", IMPLIES(value != 0, !isNullIdentification(identification, _identificationSize))); ASSERT("Valid identification", IMPLIES(value == 0, !isNullIdentification(identification, _identificationSize))); OMStorable* oldObject = _pointer; _pointer = const_cast<OMStorable*>(value); memcpy(_identification, identification, _identificationSize); #if defined(OM_VALIDATE_WEAK_REFERENCES) #if 0 ASSERT("Consistent source and target", IMPLIES(_pointer != 0, set()->contains(_identification))); #endif #endif POSTCONDITION("Element properly set", _pointer == value); return oldObject; }
// @mfunc Constructor. OMObjectReference::OMObjectReference(void) : _property(0), _pointer(0) { TRACE("OMObjectReference::OMObjectReference"); POSTCONDITION("void", isVoid()); }
// @mfunc Load the persisted representation of this // <c OMStrongObjectReference>. void OMStrongObjectReference::load(void) { TRACE("OMStrongObjectReference::load"); PRECONDITION("Not already loaded", !isLoaded()); PRECONDITION("Valid container property", _property != 0); // open the sub-storage // OMStorable* containingObject = _property->propertySet()->container(); OMStoredObject* store = containingObject->store(); ASSERT("Valid store", store != 0); OMStoredObject* subStorage = store->open(_name); // restore referenced object from the sub-storage // OMStorable* object = subStorage->restoreObject(*this); ASSERT("Object properly restored", object != 0); // place a pointer to the newly restored object in this element // setValue(object); setLoaded(); // notify the client that the object has just been restored // ASSERT("Valid containing property", _property != 0); OMFile* file = _property->propertySet()->container()->file(); ASSERT("Valid file", file != 0); _pointer->onRestore(file->clientOnSaveContext()); POSTCONDITION("Property properly loaded", isLoaded()); }
// @mfunc Set the value of this <c OMStrongObjectReference>. // The value is a pointer to the referenced <c OMStorable>. // @parm A pointer to the new <c OMStorable>. // @rdesc A pointer to previous <c OMStorable>, if any. OMStorable* OMStrongObjectReference::setValue(const OMStorable* value) { TRACE("OMStrongObjectReference::setValue"); PRECONDITION("Valid container property", _property != 0); // Detach the old object // OMStorable* oldObject = _pointer; if (oldObject != 0) { oldObject->detach(); } // Set the element to contain the new object // _pointer = const_cast<OMStorable*>(value); OMStorable* newObject = _pointer; // Attach the new object // if (newObject != 0) { OMStorable* container = _property->propertySet()->container(); newObject->attach(container, _name); } setLoaded(); POSTCONDITION("Element properly set", _pointer == newObject); return oldObject; }
SDMolSupplier::SDMolSupplier(const std::string &fileName, bool sanitize, bool removeHs, bool strictParsing) { init(); // FIX: this binary mode of opening file is here because of a bug in VC++ 6.0 // the function "tellg" does not work correctly if we do not open it this way // Jan 2009: Confirmed that this is still the case in visual studio 2008 std::istream *tmpStream = 0; tmpStream = static_cast<std::istream *>( new std::ifstream(fileName.c_str(), std::ios_base::binary)); if (!tmpStream || (!(*tmpStream)) || (tmpStream->bad())) { std::ostringstream errout; errout << "Bad input file " << fileName; throw BadFileException(errout.str()); } // dp_inStream = static_cast<std::istream *>(tmpStream); dp_inStream = tmpStream; df_owner = true; d_molpos.push_back(dp_inStream->tellg()); df_sanitize = sanitize; df_removeHs = removeHs; df_strictParsing = strictParsing; this->checkForEnd(); if (df_end) { // checkForEnd() sets d_len if we're at EOF. undo that (was GitHub issue // 19): d_len = 0; } POSTCONDITION(dp_inStream, "bad instream"); }
SmilesMolSupplier::SmilesMolSupplier(const std::string &fileName, const std::string &delimiter, int smilesColumn, int nameColumn, bool titleLine, bool sanitize) { init(); // FIX: this binary mode of opening file is here because of a bug in VC++ 6.0 // the function "tellg" does not work correctly if we do not open it this way // Need to check if this has been fixed in VC++ 7.0 std::ifstream *tmpStream = new std::ifstream(fileName.c_str(), std::ios_base::binary); if (!tmpStream || (!(*tmpStream)) || (tmpStream->bad())) { std::ostringstream errout; errout << "Bad input file " << fileName; throw BadFileException(errout.str()); } dp_inStream = static_cast<std::istream *>(tmpStream); CHECK_INVARIANT(dp_inStream, "bad instream"); CHECK_INVARIANT(!(dp_inStream->eof()), "early EOF"); d_delim = delimiter; df_sanitize = sanitize; df_title = titleLine; d_smi = smilesColumn; d_name = nameColumn; df_end = false; // if(d_title) processTitleLine(); this->checkForEnd(); POSTCONDITION(dp_inStream, "bad instream"); }
void METH(open)() { int i; CODEC_INIT_T status; STEREOWIDENER_DUMMY_INTERFACE_T *interface_fe = (STEREOWIDENER_DUMMY_INTERFACE_T *) &interface; for (i=0; i<MEM_BANK_COUNT; i++){ interface_fe->heap_info_table[i] = &mHeapInfo[i]; } status = m2s_init(&mStereoEnhancerData,interface_fe); POSTCONDITION(status == INIT_OK); ATTR(XMemUsed) = mHeapInfo[MEM_XTCM].SizeAllocated; ATTR(YMemUsed) = mHeapInfo[MEM_YTCM].SizeAllocated; ATTR(DDR24MemUsed) = mHeapInfo[MEM_DDR24].SizeAllocated; ATTR(DDR16MemUsed) = mHeapInfo[MEM_DDR16].SizeAllocated; ATTR(ESR24MemUsed) = mHeapInfo[MEM_ESR24].SizeAllocated; ATTR(ESR16MemUsed) = mHeapInfo[MEM_ESR16].SizeAllocated; if (disp_mem.displayMemPreset != NULL) { disp_mem.displayMemPreset(ATTR(XMemUsed), ATTR(YMemUsed), ATTR(DDR24MemUsed), ATTR(DDR16MemUsed), ATTR(ESR24MemUsed), ATTR(ESR16MemUsed)); } }
// @mfunc Open this <c OMFile>. // @precondition <f !isOpen()> // @precondition <f !isClosed()> // @postcondition <f isOpen()> void OMFile::open(void) { TRACE("OMFile::open"); PRECONDITION("Not already open", !isOpen()); PRECONDITION("Never been opened", !isClosed()); PRECONDITION("Valid mode", (_mode == readOnlyMode) || (_mode == writeOnlyMode) || (_mode == modifyMode)); if (_isNew) { // new file - create ASSERT("Correct mode for new file", _mode != readOnlyMode); if (_mode == modifyMode) { createModify(); } else { // _mode == writeOnly createWrite(); } } else { // existing file - open ASSERT("Correct mode for existing file", (_mode == readOnlyMode) || (_mode == modifyMode)); if (_mode == readOnlyMode) { openRead(); } else { // _mode == modifyMode openModify(); } ASSERT("No root object", _root == 0); _root = restoreRoot(); } _isOpen = true; POSTCONDITION("Open", isOpen()); }
// @mfunc The unique key of this <c OMStrongReferenceSetElement>. // @rdesc The unique key of this <c OMStrongReferenceSetElement>. void* OMStrongReferenceSetElement::identification(void) const { TRACE("OMStrongReferenceSetElement::identification"); POSTCONDITION("Valid identification", _identification != 0); return _identification; }
// @mfunc Constructor. Create an <c OMFile> object representing // an existing external file on the given <c OMRawStorage>. OMFile::OMFile(OMRawStorage* rawStorage, void* clientOnRestoreContext, OMStoredObjectEncoding encoding, const OMAccessMode mode, const OMClassFactory* factory, OMDictionary* dictionary, const OMLoadMode loadMode) : _root(0), _rootStore(0), _dictionary(dictionary), _classFactory(factory), _referencedProperties(0), _mode(mode), _loadMode(loadMode), _fileName(0), _encoding(encoding), _clientOnSaveContext(0), _clientOnRestoreContext(clientOnRestoreContext), _rawStorage(rawStorage), _isOpen(false), _isClosed(false), _isNew(false), _isValid(true), _byteOrder(unspecified) { TRACE("OMFile::OMFile"); PRECONDITION("Valid raw storage", _rawStorage != 0); PRECONDITION("Consistent access modes", IMPLIES(((mode == modifyMode) || (mode == writeOnlyMode)), rawStorage->isWritable())); PRECONDITION("Valid dictionary", _dictionary != 0); POSTCONDITION("File not yet open", !_isOpen); }
void OMFile::finalize(void) { TRACE("OMFile::finalize"); POSTCONDITION("Valid factory", _factory ); PRECONDITION("Valid default encoding map", _defaultEncodings ); delete _factory; _factory = 0; delete _defaultEncodings; _defaultEncodings = 0; POSTCONDITION("No valid factory", _factory == 0); POSTCONDITION("No valid default encoding map", _defaultEncodings == 0); }
void OMFile::openRead(void) { TRACE("OMFile::openRead"); OMStoredObjectFactory* factory = 0; // if client said DontCare, get from isRecognized(_rawStorage, _encoding) if( nullOMStoredObjectEncoding == _encoding ) { #if defined(OM_DEBUG) bool result = #endif isRecognized(_rawStorage, _encoding); ASSERT("Recognized file", result); factory = findFactory(_encoding); ASSERT("Recognized file encoding", factory != 0); } else { // else get exact: findfactory->isRecognized(_rawStorage) factory = findFactory(_encoding); ASSERT("Recognized file encoding", factory != 0); #if defined(OM_DEBUG) bool result = #endif factory->isRecognized(_rawStorage); ASSERT("Recognized file", result); } _rootStore = factory->openRead(_rawStorage); POSTCONDITION("Valid store", _rootStore != 0); }
struct reaccs_molecule_t *molToReaccs(const ROMol &mol) { std::string molB = MolToMolBlock(mol, true); Utils::LocaleSwitcher ls; struct reaccs_molecule_t *res = MolStr2Mol((char *)molB.c_str()); POSTCONDITION(res, "could not build a molecule"); return res; }
// @mfunc Constructor. OMStrongObjectReference::OMStrongObjectReference(void) : OMObjectReference(), _isLoaded(true), _name(0) { TRACE("OMStrongObjectReference::OMStrongObjectReference"); POSTCONDITION("void", isVoid()); }
struct reaccs_molecule_t *reaccsGetCoords(struct reaccs_molecule_t *molPtr) { PRECONDITION(molPtr, "bad molecule"); RecolorMolecule(molPtr); struct reaccs_molecule_t *res = LayoutMolecule(molPtr); POSTCONDITION(res, "could not layout molecule"); return res; };
OMDataStreamAccess* OMDataStreamProperty::streamAccess(void) const { TRACE("OMDataStreamProperty::streamAccess"); PRECONDITION("Has stream access", hasStreamAccess()); OMDataStreamAccess* result = _streamAccess; POSTCONDITION("Valid result", result != 0); return result; }
// @mfunc Set the size, in bytes, of the data in this // <c OMDataStreamProperty>. // @rdesc The new size, in bytes, of the data in this // <c OMDataStreamProperty>. void OMDataStreamProperty::setSize(const OMUInt64 newSize) { TRACE("OMDataStreamProperty::setSize"); stream()->setSize(newSize); setPresent(); POSTCONDITION("Size properly set", size() == newSize); }
// @mfunc Set the current position for <f read()> and <f write()>, as an // offset in bytes from the begining of the data stream. // @parm The position to use for subsequent calls to read() and // write() on this stream. The position is specified as an // offset in bytes from the begining of the data stream. // @this const void OMDataStreamProperty::setPosition(const OMUInt64 offset) const { TRACE("OMDataStreamProperty::setPosition"); stream()->setPosition(offset); POSTCONDITION("Position properly set", position() == offset); }
void OMDataStreamProperty::clearStreamAccess(void) { TRACE("OMDataStreamProperty::clearStreamAccess"); PRECONDITION("Existing stream access", hasStreamAccess()); delete _streamAccess; _streamAccess = 0; POSTCONDITION("No stream access", !hasStreamAccess()); }
void OMDataStreamProperty::setStreamAccess(OMDataStreamAccess* streamAccess) { TRACE("OMDataStreamProperty::setStreamAccess"); PRECONDITION("No existing stream access", !hasStreamAccess()); _streamAccess = streamAccess; setPresent(); POSTCONDITION("Has stream access", hasStreamAccess()); }
// @mfunc The unique key of this <c OMWeakReferenceSetElement>. // @rdesc The unique key of this <c OMWeakReferenceSetElement>. const void* OMWeakReferenceSetElement::identification(void) const { TRACE("OMWeakReferenceSetElement::identification"); POSTCONDITION("Valid identification", _reference.identification() != 0); return _reference.identification(); }
void OMDataStreamProperty::create(void) { TRACE("OMDataStreamProperty::create"); PRECONDITION("Stream not already created", _stream == 0); _stream = store()->createStoredStream(*this); _exists = true; POSTCONDITION("Stream opened", _stream != 0); }
OMFile::FactorySetIterator* OMFile::factories(void) { TRACE("OMFile::factories"); ASSERT("Valid factory", _factory != 0); FactorySetIterator* result = new FactorySetIterator(*_factory, OMBefore); POSTCONDITION("Valid iterator", result != 0); return result; }
// @mfunc Specify the essence element key for this stream. // @parm The essence element key. void OMDataStreamProperty::setEssenceElementKey(const OMKLVKey& key) { TRACE("OMDataStreamProperty::setEssenceElementKey"); PRECONDITION("Stream supports essence element keys", hasEssenceElementKey()); stream()->setEssenceElementKey(key); POSTCONDITION("Essence element key set", essenceElementKey() == key); }