H3D API  2.4.1
X3DUrlObject.h
Go to the documentation of this file.
1 // Copyright 2004-2019, SenseGraphics AB
3 //
4 // This file is part of H3D API.
5 //
6 // H3D API is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // H3D API is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with H3D API; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // A commercial license is also available. Please contact us at
21 // www.sensegraphics.com for more information.
22 //
23 //
27 //
29 #ifndef __X3DURLOBJECT_H__
30 #define __X3DURLOBJECT_H__
31 
32 #include <H3D/Node.h>
33 #include <H3D/FieldTemplates.h>
34 #include <H3D/MFString.h>
35 
36 namespace H3D {
51  class H3DAPI_API X3DUrlObject {
52  public:
53 
55  X3DUrlObject( Inst< MFString> _url = 0 );
56 
57  virtual ~X3DUrlObject() {}
58 
60  typedef enum {
68  FAILED
69  } LoadStatus;
70 
74  virtual LoadStatus loadStatus() {
75  if( url_used != "" ) return X3DUrlObject::LOADED;
76  else return X3DUrlObject::FAILED;
77  }
78 
84  virtual H3DFloat loadProgress() {
85  if( loadStatus() == LOADED ) return 1;
86  else return 0;
87  }
88 
90  inline void setURLUsed( const string &_url_used ) {
91  url_used = _url_used;
92  }
93 
95  inline const string &getURLUsed() {
96  return url_used;
97  }
98 
100  inline void setURLBase( const string &_url_base ) {
101  url_base = _url_base;
102  }
103 
105  inline const string &getURLBase() {
106  return url_base;
107  }
108 
110  string resolveURLAsFile( const string &url,
111  bool *is_tmp_file = NULL );
112 
114  string resolveURLAsString( const string &url );
115 
119  bool removeTmpFile( const string &file );
120 
122  H3DUniquePtr< MFString > url;
123  protected:
125  string resolveURL ( const string& _url, bool return_contents, bool *is_tmp_file = NULL );
126 
128  void addInlinePrefix( const string &s );
129 
132  int getInlinedContentOffset( const std::string& url );
133 
137  string url_used;
138 
142  string url_base;
143 
147  };
148 }
149 
150 #endif
Contains different templates to modify field behaviour.
Contains the MFString field class.
Node base class.
This abstract interface is inherited by all nodes that contain data located on the World Wide Web,...
Definition: X3DUrlObject.h:51
list< string > supported_inline_prefixes
A list of inline prefixes that are supported by this url object.
Definition: X3DUrlObject.h:146
void setURLUsed(const string &_url_used)
Set the url that is currently loaded.
Definition: X3DUrlObject.h:90
LoadStatus
The load status of the given url.
Definition: X3DUrlObject.h:60
@ FAILED
The loading of the url failed.
Definition: X3DUrlObject.h:68
@ INIT
The url has not been tried to load yet.
Definition: X3DUrlObject.h:62
@ LOADED
The url has been successfully loaded.
Definition: X3DUrlObject.h:64
@ LOADING
The url is currently loading.
Definition: X3DUrlObject.h:66
virtual H3DFloat loadProgress()
The loadProgress() functions returns a value between 0 and 1 indicating how much of the current url h...
Definition: X3DUrlObject.h:84
void setURLBase(const string &_url_base)
Set the url base address.
Definition: X3DUrlObject.h:100
string url_base
The base URL for urls in this url object.
Definition: X3DUrlObject.h:142
virtual LoadStatus loadStatus()
The loadStatus function returns the status of the loading of the current urls in order to be used wit...
Definition: X3DUrlObject.h:74
const string & getURLUsed()
Get the url that is currently loaded.
Definition: X3DUrlObject.h:95
string url_used
If loadStatus() returns LOADED this string should contain the url that is loaded.
Definition: X3DUrlObject.h:137
H3DUniquePtr< MFString > url
The urls in decreasing order of preference.
Definition: X3DUrlObject.h:122
const string & getURLBase()
Get the current url base address.
Definition: X3DUrlObject.h:105
float H3DFloat
H3D API namespace.
Definition: Anchor.h:38