En train de créer un système XML en utilisant Ogre et la STL. Comme preuve de concept, nous essayons de l'obtenir pour afficher le contenu du fichier XML dans notre fichier journal. Malheureusement, notre code actuel ne compilera pas, et nous ne savons pas pourquoi. Le code correspondant suit:Flux personnalisé/streambuf utilisant Ogre3d avec des erreurs de surcharge ambiguës
Voici une classe de flux dont nous avons hérité pour simplifier la gestion d'un streambuf personnalisé. La principale raison pour laquelle il existe pour supprimer le streambuf personnalisé dans son destructeur.
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();
};
Voici la définition de la classe streambuf personnalisée. Il utilise un ogreDatastreambuf pour lire les fichiers compressés dans gérés par la bibliothèque de ressources 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);
};
}
Voici le morceau de code essayer d'utiliser cette classe de flux. TheWorld-> LogStream est un 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;
Toute tentative de compilation produit cette erreur:
error: ambiguous overload for 'operator>>' in '* XMLptr >> XMLStringStream'
J'ai fait des recherches sur cette erreur, et la seule chose que je peux trouver à ce sujet ... il est dû à quelque chose d'être déclaré const que shouldn » t. Ce n'est pas le cas de notre code pour autant que nous puissions le dire. Donc, je ne sais pas pourquoi cela se passe, ou comment y remédier. Toute idée serait grandement appréciée.