diff --git a/include/stdex/idrec.h b/include/stdex/idrec.h index 4ab1db21e..da5156770 100644 --- a/include/stdex/idrec.h +++ b/include/stdex/idrec.h @@ -28,6 +28,28 @@ namespace stdex { namespace idrec { + /// + /// Reads record ID + /// + /// \param[in] stream Input stream + /// \param[out] id Record ID + /// \param[in] end Position limit. Default is -1 (no limit). + /// + /// \returns + /// - true when succeeded + /// - false otherwise + /// + template + inline bool read_id(_In_ std::istream& stream, _Out_ T_ID &id, _In_opt_ std::streamoff end = (std::streamoff)-1) + { + if (end == (std::streamoff)-1 || stream.tellg() < end) { + stream.read((char*)&id, sizeof(id)); + return stream.good(); + } else + return false; + } + + /// /// Skips current record data ///