Skip to content

Commit

Permalink
remove get_ prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
jdroenner committed Jun 24, 2016
1 parent b0baa92 commit a4037b5
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 46 deletions.
6 changes: 3 additions & 3 deletions examples/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ fn main() {
use gdal::metadata::Metadata;

let driver = gdal::raster::driver::Driver::get("mem").unwrap();
println!("driver description: {:?}", driver.get_description());
println!("driver description: {:?}", driver.description());

let path = Path::new("./fixtures/tinymarble.png");
let dataset = Dataset::open(path).unwrap();
println!("dataset description: {:?}", dataset.get_description());
println!("dataset description: {:?}", dataset.description());

let key = "INTERLEAVE";
let domain = "IMAGE_STRUCTURE";
let meta = dataset.get_metadata_item(key, domain);
let meta = dataset.metadata_item(key, domain);
println!("domain: {:?} key: {:?} -> value: {:?}", domain, key, meta);

}
14 changes: 7 additions & 7 deletions examples/rasterband.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ fn main() {

let path = Path::new("./fixtures/tinymarble.png");
let dataset = Dataset::open(path).unwrap();
println!("dataset description: {:?}", dataset.get_description());
println!("dataset description: {:?}", dataset.description());

let rasterband: RasterBand = dataset.get_rasterband(1).unwrap();
println!("rasterband description: {:?}", rasterband.get_description());
println!("rasterband no_data_value: {:?}", rasterband.get_no_data_value());
println!("rasterband type: {:?}", rasterband.get_band_type());
println!("rasterband scale: {:?}", rasterband.get_scale());
println!("rasterband offset: {:?}", rasterband.get_offset());
let rasterband: RasterBand = dataset.rasterband(1).unwrap();
println!("rasterband description: {:?}", rasterband.description());
println!("rasterband no_data_value: {:?}", rasterband.no_data_value());
println!("rasterband type: {:?}", rasterband.band_type());
println!("rasterband scale: {:?}", rasterband.scale());
println!("rasterband offset: {:?}", rasterband.offset());
let rv = rasterband.read_as::<u8>(
(20, 30),
(2, 3),
Expand Down
2 changes: 1 addition & 1 deletion src/gdal_major_object.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use libc::{c_void};

pub trait MajorObject {
unsafe fn get_gdal_object_ptr(&self) -> *const c_void;
unsafe fn gdal_object_ptr(&self) -> *const c_void;
}
10 changes: 5 additions & 5 deletions src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ extern {

pub trait Metadata: MajorObject {

fn get_description(&self) -> Option<String>{
let c_res = unsafe { GDALGetDescription(self.get_gdal_object_ptr())};
fn description(&self) -> Option<String>{
let c_res = unsafe { GDALGetDescription(self.gdal_object_ptr())};
if c_res.is_null() {
None
} else {
Some(_string(c_res))
}
}

fn get_metadata_item(&self, key: &str, domain: &str) -> Option<String> {
fn metadata_item(&self, key: &str, domain: &str) -> Option<String> {
if let Ok(c_key) = CString::new(key.to_owned()) {
if let Ok(c_domain) = CString::new(domain.to_owned()){
let c_res = unsafe { GDALGetMetadataItem(self.get_gdal_object_ptr(), c_key.as_ptr(), c_domain.as_ptr())};
let c_res = unsafe { GDALGetMetadataItem(self.gdal_object_ptr(), c_key.as_ptr(), c_domain.as_ptr())};
if !c_res.is_null() {
return Some(_string(c_res));
}
Expand All @@ -37,7 +37,7 @@ pub trait Metadata: MajorObject {
if let Ok(c_key) = CString::new(key.to_owned()){
if let Ok(c_domain) = CString::new(domain.to_owned()){
if let Ok(c_value) = CString::new(value.to_owned()){
let c_res = unsafe { GDALSetMetadataItem(self.get_gdal_object_ptr(), c_key.as_ptr(), c_value.as_ptr(), c_domain.as_ptr())};
let c_res = unsafe { GDALSetMetadataItem(self.gdal_object_ptr(), c_key.as_ptr(), c_value.as_ptr(), c_domain.as_ptr())};
if c_res == 0 {
return Ok(());
}
Expand Down
14 changes: 7 additions & 7 deletions src/raster/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct Dataset {
}

impl MajorObject for Dataset {
unsafe fn get_gdal_object_ptr(&self) -> *const c_void {
unsafe fn gdal_object_ptr(&self) -> *const c_void {
self.c_dataset
}
}
Expand Down Expand Up @@ -51,7 +51,7 @@ impl Dataset {
}


pub fn get_rasterband<'a>(&'a self, band_index: isize) -> Option<RasterBand<'a>> {
pub fn rasterband<'a>(&'a self, band_index: isize) -> Option<RasterBand<'a>> {
unsafe {
let c_band = gdal::GDALGetRasterBand(self.c_dataset, band_index as c_int);
if c_band.is_null() {
Expand Down Expand Up @@ -134,8 +134,8 @@ impl Dataset {
};
}

pub fn get_band_type(&self, band_index: isize) -> Option<GDALDataType> {
self.get_rasterband(band_index).map(|band| band.get_band_type())
pub fn band_type(&self, band_index: isize) -> Option<GDALDataType> {
self.rasterband(band_index).map(|band| band.band_type())
}

/// Read a 'Buffer<u8>' from a 'Dataset'.
Expand Down Expand Up @@ -167,7 +167,7 @@ impl Dataset {
band_index: isize,
) -> Option<Buffer<T>>
{
self.get_rasterband(band_index).map(|band| band.read_band_as())
self.rasterband(band_index).map(|band| band.read_band_as())
}

/// Read a 'Buffer<T>' from a 'Dataset'. T implements 'GdalType'
Expand All @@ -184,7 +184,7 @@ impl Dataset {
size: (usize, usize),
) -> Option<Buffer<T>>
{
self.get_rasterband(band_index).map(|band| band.read_as(window, window_size, size))
self.rasterband(band_index).map(|band| band.read_as(window, window_size, size))
}

/// Write a 'Buffer<T>' into a 'Dataset'.
Expand All @@ -199,7 +199,7 @@ impl Dataset {
window_size: (usize, usize),
buffer: Buffer<T>
) {
self.get_rasterband(band_index).expect("Invalid RasterBand").write(window, window_size, buffer)
self.rasterband(band_index).expect("Invalid RasterBand").write(window, window_size, buffer)
}

}
Expand Down
2 changes: 1 addition & 1 deletion src/raster/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl Driver {
}

impl MajorObject for Driver {
unsafe fn get_gdal_object_ptr(&self) -> *const c_void {
unsafe fn gdal_object_ptr(&self) -> *const c_void {
return self.c_driver;
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/raster/rasterband.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl <'a> RasterBand<'a> {
};
}

pub fn get_band_type(&self) -> gdal_enums::GDALDataType {
pub fn band_type(&self) -> gdal_enums::GDALDataType {

let gdal_type: c_int;
unsafe{
Expand All @@ -114,7 +114,7 @@ impl <'a> RasterBand<'a> {
gdal_enums::GDALDataType::from_c_int(gdal_type)
}

pub fn get_no_data_value(&self) ->Option<f64> {
pub fn no_data_value(&self) ->Option<f64> {
unsafe {
let mut pb_success: c_int = 1;
let raw_pb_success = &mut pb_success as *mut c_int;
Expand All @@ -126,7 +126,7 @@ impl <'a> RasterBand<'a> {
None
}

pub fn get_scale(&self) ->Option<f64> {
pub fn scale(&self) ->Option<f64> {
unsafe {
let mut pb_success: c_int = 1;
let raw_pb_success = &mut pb_success as *mut c_int;
Expand All @@ -138,7 +138,7 @@ impl <'a> RasterBand<'a> {
None
}

pub fn get_offset(&self) ->Option<f64> {
pub fn offset(&self) ->Option<f64> {
unsafe {
let mut pb_success: c_int = 1;
let raw_pb_success = &mut pb_success as *mut c_int;
Expand All @@ -152,7 +152,7 @@ impl <'a> RasterBand<'a> {
}

impl<'a> MajorObject for RasterBand<'a> {
unsafe fn get_gdal_object_ptr(&self) -> *const c_void {
unsafe fn gdal_object_ptr(&self) -> *const c_void {
self.c_rasterband
}
}
Expand Down
30 changes: 15 additions & 15 deletions src/raster/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,20 @@ fn test_get_dataset_driver() {
fn test_get_description() {

let driver = Driver::get("mem").unwrap();
assert_eq!(driver.get_description(), Some("MEM".to_owned()));
assert_eq!(driver.description(), Some("MEM".to_owned()));
}

#[test]
fn test_get_metadata_item() {
let dataset = Dataset::open(fixture!("tinymarble.png")).unwrap();
let key = "None";
let domain = "None";
let meta = dataset.get_metadata_item(key, domain);
let meta = dataset.metadata_item(key, domain);
assert_eq!(meta, None);

let key = "INTERLEAVE";
let domain = "IMAGE_STRUCTURE";
let meta = dataset.get_metadata_item(key, domain);
let meta = dataset.metadata_item(key, domain);
assert_eq!(meta, Some(String::from("PIXEL")));
}

Expand All @@ -146,7 +146,7 @@ fn test_set_metadata_item() {
let result = dataset.set_metadata_item(key, value, domain);
assert_eq!(result, Ok(()));

let result = dataset.get_metadata_item(key, domain);
let result = dataset.metadata_item(key, domain);
assert_eq!(Some(value.to_owned()), result);
}

Expand All @@ -166,7 +166,7 @@ fn test_create_with_band_type() {
assert_eq!(dataset.size(), (10, 20));
assert_eq!(dataset.count(), 3);
assert_eq!(dataset.driver().short_name(), "MEM");
assert_eq!(dataset.get_band_type(1), Some(GDALDataType::GDT_Float32))
assert_eq!(dataset.band_type(1), Some(GDALDataType::GDT_Float32))
}

#[test]
Expand Down Expand Up @@ -213,7 +213,7 @@ fn test_read_raster_as() {
assert_eq!(rv.data, vec!(7, 7, 7, 10, 8, 12));
assert_eq!(rv.size.0, 2);
assert_eq!(rv.size.1, 3);
assert_eq!(dataset.get_band_type(1), Some(GDALDataType::GDT_Byte));
assert_eq!(dataset.band_type(1), Some(GDALDataType::GDT_Byte));
}

#[test]
Expand All @@ -228,23 +228,23 @@ fn test_read_full_raster_as() {
fn test_get_band_type() {
let driver = Driver::get("MEM").unwrap();
let dataset = driver.create("", 20, 10, 1).unwrap();
assert_eq!(dataset.get_band_type(1), Some(GDALDataType::GDT_Byte));
assert_eq!(dataset.get_band_type(2), None);
assert_eq!(dataset.band_type(1), Some(GDALDataType::GDT_Byte));
assert_eq!(dataset.band_type(2), None);
}

#[test]
fn test_get_rasterband() {
let driver = Driver::get("MEM").unwrap();
let dataset = driver.create("", 20, 10, 1).unwrap();
let rasterband = dataset.get_rasterband(1);
let rasterband = dataset.rasterband(1);
assert!(rasterband.is_some())
}

#[test]
fn test_get_no_data_value() {
let dataset = Dataset::open(fixture!("tinymarble.png")).unwrap();
let rasterband = dataset.get_rasterband(1).unwrap();
let no_data_value = rasterband.get_no_data_value();
let rasterband = dataset.rasterband(1).unwrap();
let no_data_value = rasterband.no_data_value();
assert!(no_data_value.is_none());

// let dataset = Dataset::open(fixture!("bluemarble.tif")).unwrap();
Expand All @@ -256,15 +256,15 @@ fn test_get_no_data_value() {
#[test]
fn test_get_scale() {
let dataset = Dataset::open(fixture!("tinymarble.png")).unwrap();
let rasterband = dataset.get_rasterband(1).unwrap();
let scale = rasterband.get_scale();
let rasterband = dataset.rasterband(1).unwrap();
let scale = rasterband.scale();
assert_eq!(scale, Some(1.0));
}

#[test]
fn test_get_offset() {
let dataset = Dataset::open(fixture!("tinymarble.png")).unwrap();
let rasterband = dataset.get_rasterband(1).unwrap();
let offset = rasterband.get_offset();
let rasterband = dataset.rasterband(1).unwrap();
let offset = rasterband.offset();
assert_eq!(offset, Some(0.0));
}
2 changes: 1 addition & 1 deletion src/vector/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct Dataset {
}

impl MajorObject for Dataset {
unsafe fn get_gdal_object_ptr(&self) -> *const c_void {
unsafe fn gdal_object_ptr(&self) -> *const c_void {
self.c_dataset
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/vector/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct Layer {
}

impl MajorObject for Layer {
unsafe fn get_gdal_object_ptr(&self) -> *const c_void {
unsafe fn gdal_object_ptr(&self) -> *const c_void {
self.c_layer
}
}
Expand Down

0 comments on commit a4037b5

Please sign in to comment.