C++ 使用Ogre3d的自定义流/streambuf具有不明确的重载错误
目前正在尝试使用Ogre和STL创建XML系统。作为概念证明,我们试图让它将XML文件的内容输出到日志文件中。遗憾的是,我们当前的代码无法编译,我们也不知道为什么。有关守则如下: 这里是我们从中继承的一个stream类,用于简化自定义streambuf的管理。它存在的主要原因是删除其析构函数中的自定义streambufC++ 使用Ogre3d的自定义流/streambuf具有不明确的重载错误,c++,iostream,std,ogre3d,C++,Iostream,Std,Ogre3d,目前正在尝试使用Ogre和STL创建XML系统。作为概念证明,我们试图让它将XML文件的内容输出到日志文件中。遗憾的是,我们当前的代码无法编译,我们也不知道为什么。有关守则如下: 这里是我们从中继承的一个stream类,用于简化自定义streambuf的管理。它存在的主要原因是删除其析构函数中的自定义streambuf class ResourceInputStream : public std::istream { private: internal::OgreData
class ResourceInputStream : public std::istream
{
private:
internal::OgreDataStreamBuf* OgreBuffer;
ResourceManager* Manager;
/// @internal
/// @brief Called by the constructors to actually construct this class
/// @param InputBuffer A pointer to an internal::OgreDataStreamBuf. A buffer to read from the disk access subsystem (which happens to be part of Ogre). This Stream will assume ownership of this buffer and will handle deleting it.
/// @param ResourceManager_ Currently unused, future functionality may tuse this.
void Construct(std::streambuf *InputBuffer, ResourceManager* ResourceManager_);
protected:
public:
/// @brief Descriptive Constructor
/// @param InputBuffer A pointer to an internal::OgreDataStreamBuf. A buffer to read from the disk access subsystem (which happens to be part of Ogre). This Stream will assume ownership of this buffer and will handle deleting it.
/// @param ResourceManager_ Currently unused, future functionality may tuse this.
/// @warning Do not delete the InputBuffer you pass in, this class will assume owner ship and delete it on it's own
ResourceInputStream(std::streambuf *InputBuffer, ResourceManager* ResourceManager_) :
std::istream(InputBuffer)
{ this->Construct(InputBuffer, ResourceManager_); }
/// @brief Tears down the Stream, and Delete the Buffer Passed in.
virtual ~ResourceInputStream();
};
下面是自定义streambuf类的定义。它使用ogreDatastreambuf从中读取由Ogre资源库管理的压缩文件:
class OgreDataStreamBuf : public std::streambuf
{
protected:
/// @brief a shard_ptr to the internal Ogre Datastream
Ogre::DataStreamPtr OgreStream;
public:
/// @brief constructor
/// @param Datum A pointer to the Ogre Datastream that this stream will use
OgreDataStreamBuf(const Ogre::DataStreamPtr& Datum) : OgreStream(Datum)
{
#ifdef PHYSDEBUG
World::GetWorldPointer()->Log("Entering/Exiting OgreDataStreamBuf Constructor");
#endif
}
/// @brief Should get the amount of characters left in the sequence
/// @returns -1 if no estimate could be made, other wise this returns an estimate of the amount of bytes in the buffer
std::streamsize showmanyc();
/// @brief Gets a sequence of characters
/// @param s a Pointer to where the characters should go
/// @param n How many characters
/// @return This returns the amount of characters retrieved
std::streamsize xsgetn(char* s, std::streamsize n);
/// @brief puts a sequence of characters in
/// @param s a Pointer to the characters
/// @param n How many characters
/// @return This returns the amount of characters inserted
/// @detail currently unimplimented
std::streamsize xsputn(const char_type*, std::streamsize n);
};
}
下面是一段试图使用这个流类的代码。world->LogStream是一个std::stringstream
ResourceInputStream* XMLptr = TheWorld->GetResourceManager()->GetResourceStream("test.xml");
std::stringstream XMLStringStream;
(*XMLptr) >> XMLStringStream;
String ShouldHaveXML(XMLStringStream.str());
TheWorld->LogStream << "ShouldHaveXML: " << ShouldHaveXML << endl << "End XML Logging" <<endl;
TheWorld->Log("Delete XML Stream");
delete XMLptr;
我已经研究过这个错误,我唯一能找到的就是。。。这是因为有些东西被声明为常量而不应该。就我们所知,我们的代码并非如此。所以我不知道为什么会发生这种情况,或者如何着手解决它。如有任何见解,将不胜感激 这里似乎有很多额外的不需要的信息,问题的关键是没有从istream>>到ostream的流式传输运营商 所有的食人魔和自定义类的东西都是不需要的,与此同时,我们设法使用s的简单解决方法从类中获取数据:
ResourceInputStream* XMLptr = TheWorld->GetResourceManager()->GetResourceStream("test.xml");
char chararray[401];
chararray[400]='\0';
XMLptr->read(chararray, 400);
String ShouldHaveXML( chararray );
这只是测试代码,我总是建议在假设您读取所请求的数据量之前使用istream::gcount
ResourceInputStream* XMLptr = TheWorld->GetResourceManager()->GetResourceStream("test.xml");
char chararray[401];
chararray[400]='\0';
XMLptr->read(chararray, 400);
String ShouldHaveXML( chararray );