path.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00035 #include "path.h"
00036 #if LIBDARC_HAVE_LIBDAR_HPP
00037 #include <dar/libdar.hpp>
00038 #endif
00039
00040 NAMESPACE_LIBDAR_START
00041
00042 extern "C" dar_path *dar_path_create( char* path )
00043 {
00044 libdar::path* ret;
00045 try {
00046 ret = new libdar::path( path );
00047 } catch (...) {
00048 return NULL;
00049 }
00050 return (dar_path*)ret;
00051 }
00052
00053 extern "C" dar_path *dar_path_copy( dar_path* ref )
00054 {
00055 libdar::path* tmp = (libdar::path*)ref;
00056 libdar::path* ret = new libdar::path( *tmp );
00057 return (dar_path*)ret;
00058 }
00059
00060 extern "C" void dar_path_destroy( dar_path* ref )
00061 {
00062 libdar::path* tmp = (libdar::path*)ref;
00063 delete tmp;
00064 }
00065
00066 extern "C" bool dar_path_compare( dar_path* ref, dar_path* path )
00067 {
00068 libdar::path* r = (libdar::path*)ref;
00069 libdar::path* p = (libdar::path*)path;
00070 return *r == *p;
00071 }
00072
00073 extern "C" bool dar_path_is_relative( dar_path* ref )
00074 {
00075 libdar::path* r = (libdar::path*)ref;
00076 return r->is_relative();
00077 }
00078
00079 extern "C" bool dar_path_is_subdir_of( dar_path* ref, dar_path* path, bool case_sensit )
00080 {
00081 libdar::path* r = (libdar::path*)ref;
00082 libdar::path* p = (libdar::path*)path;
00083 return r->is_subdir_of( *p, case_sensit );
00084 }
00085
00086
00087 extern "C" char *dar_path_iterate_next( dar_path* ref )
00088 {
00089 libdar::path* r = (libdar::path*)ref;
00090 std::string tmp;
00091 if ( !(r->read_subdir(tmp)) )
00092 return NULL;
00093 char* ret = (char*)malloc(tmp.length() + 1);
00094 if (ret == NULL) { return NULL; }
00095 strcpy( ret, tmp.c_str() );
00096 return ret;
00097 }
00098
00099 extern "C" void dar_path_iterate_reset( dar_path* ref )
00100 {
00101 libdar::path* r = (libdar::path*)ref;
00102 r->reset_read();
00103 return;
00104 }
00105
00106 extern "C" bool dar_path_stack_push( dar_path* ref, dar_path* path )
00107 {
00108 libdar::path* r = (libdar::path*)ref;
00109 libdar::path* p = (libdar::path*)path;
00110 try {
00111 (*r) += (*p);
00112 } catch (...) {
00113 return false;
00114 }
00115 return true;
00116 }
00117
00118 extern "C" bool dar_path_stack_peek( dar_path* ref, char** name )
00119 {
00120 libdar::path* r = (libdar::path*)ref;
00121 std::string tmp = r->basename();
00122 *name = (char*)malloc(tmp.length() + 1);
00123 strcpy( *name, tmp.c_str() );
00124 if ( r->degre() > 1 )
00125 return true;
00126 else
00127 return false;
00128 }
00129
00130 extern "C" bool dar_path_stack_pop( dar_path* ref, char** name )
00131 {
00132 libdar::path* r = (libdar::path*)ref;
00133 std::string tmp;
00134 if ( !(r->pop(tmp)) )
00135 {
00136 *name = NULL;
00137 return false;
00138 }
00139 *name = (char*)malloc(tmp.length() + 1);
00140 if ( *name == NULL ) { return false; }
00141 strcpy( *name, tmp.c_str() );
00142 return true;
00143 }
00144
00145 extern "C" bool dar_path_stack_pop_front( dar_path* ref, char** name )
00146 {
00147 libdar::path* r = (libdar::path*)ref;
00148 std::string tmp;
00149 if ( !(r->pop_front(tmp)) )
00150 {
00151 *name = NULL;
00152 return false;
00153 }
00154 *name = (char*)malloc(tmp.length() + 1);
00155 if ( *name == NULL ) { return false; }
00156 strcpy( *name, tmp.c_str() );
00157 return true;
00158 }
00159
00160
00161 extern "C" char *dar_path_get_string( dar_path* ref )
00162 {
00163 libdar::path* r = (libdar::path*)ref;
00164 std::string tmp = r->display();
00165 char* ret = (char*)malloc(tmp.length() + 1);
00166 if ( ret == NULL ) { return false; }
00167 strcpy( ret, tmp.c_str() );
00168 return ret;
00169 }
00170
00171 extern "C" unsigned int dar_path_get_depth( dar_path* ref )
00172 {
00173 libdar::path* r = (libdar::path*)ref;
00174 return r->degre();
00175 }
00176
00177
00178
00179 NAMESPACE_LIBDAR_END
00180