root/OpenSceneGraph/trunk/src/osgDB/ReaderWriter.cpp @ 13041

Revision 13041, 6.0 kB (checked in by robert, 3 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#include <osgDB/ReaderWriter>
15#include <osgDB/Registry>
16#include <osgDB/FileNameUtils>
17#include <osgDB/FileUtils>
18#include <osgDB/Archive>
19
20using namespace osgDB;
21
22osg::Object* ReaderWriter::ReadResult::getObject() { return _object.get(); }
23osg::Image* ReaderWriter::ReadResult::getImage() { return dynamic_cast<osg::Image*>(_object.get()); }
24osg::HeightField* ReaderWriter::ReadResult::getHeightField() { return dynamic_cast<osg::HeightField*>(_object.get()); }
25osg::Node* ReaderWriter::ReadResult::getNode() { return dynamic_cast<osg::Node*>(_object.get()); }
26osgDB::Archive* ReaderWriter::ReadResult::getArchive() { return dynamic_cast<osgDB::Archive*>(_object.get()); }
27osg::Shader* ReaderWriter::ReadResult::getShader() { return dynamic_cast<osg::Shader*>(_object.get()); }
28
29osg::Object* ReaderWriter::ReadResult::takeObject() { osg::Object* obj = _object.get(); if (obj) { obj->ref(); _object=NULL; obj->unref_nodelete(); } return obj; }
30osg::Image* ReaderWriter::ReadResult::takeImage() { osg::Image* image=dynamic_cast<osg::Image*>(_object.get()); if (image) { image->ref(); _object=NULL; image->unref_nodelete(); } return image; }
31osg::HeightField* ReaderWriter::ReadResult::takeHeightField() { osg::HeightField* hf=dynamic_cast<osg::HeightField*>(_object.get()); if (hf) { hf->ref(); _object=NULL; hf->unref_nodelete(); } return hf; }
32osg::Node* ReaderWriter::ReadResult::takeNode() { osg::Node* node=dynamic_cast<osg::Node*>(_object.get()); if (node) { node->ref(); _object=NULL; node->unref_nodelete(); } return node; }
33osgDB::Archive* ReaderWriter::ReadResult::takeArchive() { osgDB::Archive* archive=dynamic_cast<osgDB::Archive*>(_object.get()); if (archive) { archive->ref(); _object=NULL; archive->unref_nodelete(); } return archive; }
34osg::Shader* ReaderWriter::ReadResult::takeShader() { osg::Shader* shader=dynamic_cast<osg::Shader*>(_object.get()); if (shader) { shader->ref(); _object=NULL; shader->unref_nodelete(); } return shader; }
35
36ReaderWriter::~ReaderWriter()
37{
38}
39
40bool ReaderWriter::acceptsExtension(const std::string& extension) const
41{
42    // check for an exact match
43    std::string lowercase_ext = convertToLowerCase(extension);
44    if (_supportedExtensions.count(lowercase_ext)!=0) return true;
45
46    // if plugin supports wildcard extension then passthrough all types
47    return (_supportedExtensions.count("*")!=0);
48}
49
50void ReaderWriter::supportsProtocol(const std::string& fmt, const std::string& description)
51{
52    Registry::instance()->registerProtocol(fmt);
53    _supportedProtocols[convertToLowerCase(fmt)] = description;
54}
55
56void ReaderWriter::supportsExtension(const std::string& fmt, const std::string& description)
57{
58    _supportedExtensions[convertToLowerCase(fmt)] = description;
59}
60
61void ReaderWriter::supportsOption(const std::string& fmt, const std::string& description)
62{
63    _supportedOptions[fmt] = description;
64}
65
66ReaderWriter::Features ReaderWriter::supportedFeatures() const
67{
68    int features = FEATURE_NONE;
69    std::string dummyFilename;
70
71    if (readObject(dummyFilename,0).status()!=ReadResult::NOT_IMPLEMENTED) features |= FEATURE_READ_OBJECT;
72    if (readImage(dummyFilename,0).status()!=ReadResult::NOT_IMPLEMENTED) features |= FEATURE_READ_IMAGE;
73    if (readHeightField(dummyFilename,0).status()!=ReadResult::NOT_IMPLEMENTED) features |= FEATURE_READ_HEIGHT_FIELD;
74    if (readShader(dummyFilename,0).status()!=ReadResult::NOT_IMPLEMENTED) features |= FEATURE_READ_SHADER;
75    if (readNode(dummyFilename,0).status()!=ReadResult::NOT_IMPLEMENTED) features |= FEATURE_READ_NODE;
76
77    osg::ref_ptr<osg::Image> image = new osg::Image;
78    osg::ref_ptr<osg::HeightField> hf = new osg::HeightField;
79    osg::ref_ptr<osg::Shader> shader = new osg::Shader;
80    osg::ref_ptr<osg::Node> node = new osg::Node;
81
82    if (writeObject(*image, dummyFilename,0).status()!=WriteResult::NOT_IMPLEMENTED) features |= FEATURE_WRITE_OBJECT;
83    if (writeImage(*image,dummyFilename,0).status()!=WriteResult::NOT_IMPLEMENTED) features |= FEATURE_WRITE_IMAGE;
84    if (writeHeightField(*hf,dummyFilename,0).status()!=WriteResult::NOT_IMPLEMENTED) features |= FEATURE_WRITE_HEIGHT_FIELD;
85    if (writeShader(*shader,dummyFilename,0).status()!=WriteResult::NOT_IMPLEMENTED) features |= FEATURE_WRITE_SHADER;
86    if (writeNode(*node, dummyFilename,0).status()!=WriteResult::NOT_IMPLEMENTED) features |= FEATURE_WRITE_NODE;
87
88    return Features(features);
89}
90
91ReaderWriter::FeatureList ReaderWriter::featureAsString(ReaderWriter::Features feature)
92{
93    typedef struct {
94        ReaderWriter::Features feature;
95        const char *s;
96    } FeatureStringList;
97
98    FeatureStringList list[] = {
99        { FEATURE_READ_OBJECT, "readObject" },
100        { FEATURE_READ_IMAGE,  "readImage" },
101        { FEATURE_READ_HEIGHT_FIELD, "readHeightField" },
102        { FEATURE_READ_NODE, "readNode" },
103        { FEATURE_READ_SHADER, "readShader" },
104        { FEATURE_WRITE_OBJECT, "writeObject" },
105        { FEATURE_WRITE_IMAGE, "writeImage" },
106        { FEATURE_WRITE_HEIGHT_FIELD, "writeHeightField" },
107        { FEATURE_WRITE_NODE, "writeNode" },
108        { FEATURE_WRITE_SHADER, "writeShader" },
109        { FEATURE_NONE,0 }
110    };
111
112    FeatureList result;
113
114    for(FeatureStringList *p=list; p->feature != 0; p++)
115    {
116        if ((feature & p->feature) != 0)
117            result.push_back(p->s);
118    }
119    return result;
120}
121
122bool ReaderWriter::fileExists(const std::string& filename, const Options* /*options*/) const
123{
124    return ::osgDB::fileExists(filename);
125}
Note: See TracBrowser for help on using the browser.