Skip to content

Commit

Permalink
BINDINGS/C++: Added ostream for common enums [closes #177]
Browse files Browse the repository at this point in the history
  • Loading branch information
HappySeaFox committed May 4, 2022
1 parent b8996aa commit 443124e
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/bindings/c++/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ add_library(sail-c++
log-c++.h
meta_data-c++.cpp
meta_data-c++.h
ostream-c++.h
ostream-c++.cpp
palette-c++.cpp
palette-c++.h
resolution-c++.cpp
Expand Down Expand Up @@ -75,6 +77,7 @@ set(PUBLIC_HEADERS "abstract_io-c++.h"
"load_options-c++.h"
"log-c++.h"
"meta_data-c++.h"
"ostream-c++.h"
"palette-c++.h"
"resolution-c++.h"
"sail-c++.h"
Expand Down
68 changes: 68 additions & 0 deletions src/bindings/c++/ostream-c++.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* This file is part of SAIL (https://github.com/smoked-herring/sail)
Copyright (c) 2022 Dmitry Baryshev
The MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

#include "sail-c++.h"

std::ostream& operator<<(std::ostream &os, SailPixelFormat pixel_format)
{
os << sail_pixel_format_to_string(pixel_format);
return os;
}

std::ostream& operator<<(std::ostream &os, SailChromaSubsampling chroma_subsampling)
{
os << sail_chroma_subsampling_to_string(chroma_subsampling);
return os;
}

std::ostream& operator<<(std::ostream &os, SailOrientation orientation)
{
os << sail_orientation_to_string(orientation);
return os;
}

std::ostream& operator<<(std::ostream &os, SailCompression compression)
{
os << sail_compression_to_string(compression);
return os;
}

std::ostream& operator<<(std::ostream &os, SailMetaData meta_data)
{
os << sail_meta_data_to_string(meta_data);
return os;
}

std::ostream& operator<<(std::ostream &os, SailResolutionUnit resolution_unit)
{
os << sail_resolution_unit_to_string(resolution_unit);
return os;
}

std::ostream& operator<<(std::ostream &os, SailCodecFeature codec_feature)
{
os << sail_codec_feature_to_string(codec_feature);
return os;
}
47 changes: 47 additions & 0 deletions src/bindings/c++/ostream-c++.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* This file is part of SAIL (https://github.com/smoked-herring/sail)
Copyright (c) 2022 Dmitry Baryshev
The MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

#ifndef SAIL_OSTREAM_CPP_H
#define SAIL_OSTREAM_CPP_H

#include <ostream>

#ifdef SAIL_BUILD
#include "common.h"
#include "export.h"
#else
#include <sail-common/common.h>
#include <sail-common/export.h>
#endif

SAIL_EXPORT std::ostream& operator<<(std::ostream &os, SailPixelFormat pixel_format);
SAIL_EXPORT std::ostream& operator<<(std::ostream &os, SailChromaSubsampling chroma_subsampling);
SAIL_EXPORT std::ostream& operator<<(std::ostream &os, SailOrientation orientation);
SAIL_EXPORT std::ostream& operator<<(std::ostream &os, SailCompression compression);
SAIL_EXPORT std::ostream& operator<<(std::ostream &os, SailMetaData meta_data);
SAIL_EXPORT std::ostream& operator<<(std::ostream &os, SailResolutionUnit resolution_unit);
SAIL_EXPORT std::ostream& operator<<(std::ostream &os, SailCodecFeature codec_feature);

#endif
10 changes: 10 additions & 0 deletions src/bindings/c++/resolution-c++.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ void resolution::set_y(double y)
d->resolution.y = y;
}

const char* resolution::resolution_unit_to_string(SailResolutionUnit resolution_unit)
{
return sail_resolution_unit_to_string(resolution_unit);
}

SailResolutionUnit resolution::resolution_unit_from_string(const std::string &str)
{
return sail_resolution_unit_from_string(str.c_str());
}

resolution::resolution(const sail_resolution *res)
: resolution()
{
Expand Down
16 changes: 16 additions & 0 deletions src/bindings/c++/resolution-c++.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,22 @@ class SAIL_EXPORT resolution
*/
void set_y(double y);

/*
* Returns a string representation of the specified resolution unit. See SailResolutionUnit.
* For example: "Micrometer" is returned for SAIL_RESOLUTION_UNIT_MICROMETER.
*
* Returns NULL if the resolution unit is not known.
*/
static const char* resolution_unit_to_string(SailResolutionUnit resolution_unit);

/*
* Returns a resolution unit from the string representation. See SailResolutionUnit.
* For example: SAIL_RESOLUTION_UNIT_MICROMETER is returned for "Micrometer".
*
* Returns SAIL_RESOLUTION_UNIT_UNKNOWN if the resolution unit is not known.
*/
static SailResolutionUnit resolution_unit_from_string(const std::string &str);

private:
/*
* Makes a deep copy of the specified resolution.
Expand Down
2 changes: 2 additions & 0 deletions src/bindings/c++/sail-c++.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
#include "load_options-c++.h"
#include "log-c++.h"
#include "meta_data-c++.h"
#include "ostream-c++.h"
#include "palette-c++.h"
#include "resolution-c++.h"
#include "save_features-c++.h"
Expand Down Expand Up @@ -99,6 +100,7 @@
#include <sail-c++/load_options-c++.h>
#include <sail-c++/log-c++.h>
#include <sail-c++/meta_data-c++.h>
#include <sail-c++/ostream-c++.h>
#include <sail-c++/palette-c++.h>
#include <sail-c++/resolution-c++.h>
#include <sail-c++/source_image-c++.h>
Expand Down

0 comments on commit 443124e

Please sign in to comment.