Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
f58c14a7
Commit
f58c14a7
authored
Mar 28, 2021
by
Max Kellermann
Committed by
Max Kellermann
Apr 06, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Java: no namespace indent
parent
a52ce7bb
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
92 additions
and
76 deletions
+92
-76
Class.hxx
src/java/Class.hxx
+12
-10
Exception.cxx
src/java/Exception.cxx
+1
-1
Exception.hxx
src/java/Exception.hxx
+11
-9
File.hxx
src/java/File.hxx
+8
-6
Global.cxx
src/java/Global.cxx
+7
-5
Global.hxx
src/java/Global.hxx
+13
-11
Object.hxx
src/java/Object.hxx
+13
-11
Ref.hxx
src/java/Ref.hxx
+19
-17
String.hxx
src/java/String.hxx
+8
-6
No files found.
src/java/Class.hxx
View file @
f58c14a7
/*
/*
* Copyright 2010-20
18
Max Kellermann <max.kellermann@gmail.com>
* Copyright 2010-20
21
Max Kellermann <max.kellermann@gmail.com>
*
*
* Redistribution and use in source and binary forms, with or without
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* modification, are permitted provided that the following conditions
...
@@ -36,23 +36,24 @@
...
@@ -36,23 +36,24 @@
#include <cassert>
#include <cassert>
namespace
Java
{
namespace
Java
{
/**
/**
* Wrapper for a local "jclass" reference.
* Wrapper for a local "jclass" reference.
*/
*/
class
Class
:
public
LocalRef
<
jclass
>
{
class
Class
:
public
LocalRef
<
jclass
>
{
public
:
public
:
Class
(
JNIEnv
*
env
,
jclass
cls
)
noexcept
Class
(
JNIEnv
*
env
,
jclass
cls
)
noexcept
:
LocalRef
<
jclass
>
(
env
,
cls
)
{}
:
LocalRef
<
jclass
>
(
env
,
cls
)
{}
Class
(
JNIEnv
*
env
,
const
char
*
name
)
noexcept
Class
(
JNIEnv
*
env
,
const
char
*
name
)
noexcept
:
LocalRef
<
jclass
>
(
env
,
env
->
FindClass
(
name
))
{}
:
LocalRef
<
jclass
>
(
env
,
env
->
FindClass
(
name
))
{}
};
};
/**
/**
* Wrapper for a global "jclass" reference.
* Wrapper for a global "jclass" reference.
*/
*/
class
TrivialClass
:
public
TrivialRef
<
jclass
>
{
class
TrivialClass
:
public
TrivialRef
<
jclass
>
{
public
:
public
:
void
Find
(
JNIEnv
*
env
,
const
char
*
name
)
noexcept
{
void
Find
(
JNIEnv
*
env
,
const
char
*
name
)
noexcept
{
assert
(
env
!=
nullptr
);
assert
(
env
!=
nullptr
);
assert
(
name
!=
nullptr
);
assert
(
name
!=
nullptr
);
...
@@ -76,7 +77,8 @@ namespace Java {
...
@@ -76,7 +77,8 @@ namespace Java {
env
->
DeleteLocalRef
(
cls
);
env
->
DeleteLocalRef
(
cls
);
return
true
;
return
true
;
}
}
};
};
}
}
// namespace Java
#endif
#endif
src/java/Exception.cxx
View file @
f58c14a7
/*
/*
* Copyright 2010-20
19
Max Kellermann <max.kellermann@gmail.com>
* Copyright 2010-20
21
Max Kellermann <max.kellermann@gmail.com>
*
*
* Redistribution and use in source and binary forms, with or without
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* modification, are permitted provided that the following conditions
...
...
src/java/Exception.hxx
View file @
f58c14a7
/*
/*
* Copyright 2010-20
19
Max Kellermann <max.kellermann@gmail.com>
* Copyright 2010-20
21
Max Kellermann <max.kellermann@gmail.com>
*
*
* Redistribution and use in source and binary forms, with or without
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* modification, are permitted provided that the following conditions
...
@@ -35,28 +35,30 @@
...
@@ -35,28 +35,30 @@
#include <jni.h>
#include <jni.h>
namespace
Java
{
namespace
Java
{
class
Exception
:
public
std
::
runtime_error
{
public
:
class
Exception
:
public
std
::
runtime_error
{
public
:
explicit
Exception
(
JNIEnv
*
env
,
jthrowable
e
)
noexcept
;
explicit
Exception
(
JNIEnv
*
env
,
jthrowable
e
)
noexcept
;
};
};
/**
/**
* Check if a Java exception has occurred, and if yes, convert
* Check if a Java exception has occurred, and if yes, convert
* it to a C++ #Exception and throw that.
* it to a C++ #Exception and throw that.
*/
*/
void
RethrowException
(
JNIEnv
*
env
);
void
RethrowException
(
JNIEnv
*
env
);
/**
/**
* Check if an exception has occurred, and discard it.
* Check if an exception has occurred, and discard it.
*
*
* @return true if an exception was found (and discarded)
* @return true if an exception was found (and discarded)
*/
*/
static
inline
bool
DiscardException
(
JNIEnv
*
env
)
noexcept
{
static
inline
bool
DiscardException
(
JNIEnv
*
env
)
noexcept
{
bool
result
=
env
->
ExceptionCheck
();
bool
result
=
env
->
ExceptionCheck
();
if
(
result
)
if
(
result
)
env
->
ExceptionClear
();
env
->
ExceptionClear
();
return
result
;
return
result
;
}
}
}
}
// namespace Java
#endif
#endif
src/java/File.hxx
View file @
f58c14a7
/*
/*
* Copyright 2010-20
18
Max Kellermann <max.kellermann@gmail.com>
* Copyright 2010-20
21
Max Kellermann <max.kellermann@gmail.com>
*
*
* Redistribution and use in source and binary forms, with or without
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* modification, are permitted provided that the following conditions
...
@@ -37,13 +37,14 @@
...
@@ -37,13 +37,14 @@
class
AllocatedPath
;
class
AllocatedPath
;
namespace
Java
{
namespace
Java
{
/**
/**
* Wrapper for a java.io.File object.
* Wrapper for a java.io.File object.
*/
*/
class
File
:
public
LocalObject
{
class
File
:
public
LocalObject
{
static
jmethodID
getAbsolutePath_method
;
static
jmethodID
getAbsolutePath_method
;
public
:
public
:
gcc_nonnull_all
gcc_nonnull_all
static
void
Initialise
(
JNIEnv
*
env
)
noexcept
;
static
void
Initialise
(
JNIEnv
*
env
)
noexcept
;
...
@@ -60,7 +61,8 @@ namespace Java {
...
@@ -60,7 +61,8 @@ namespace Java {
gcc_pure
gcc_nonnull_all
gcc_pure
gcc_nonnull_all
static
AllocatedPath
ToAbsolutePath
(
JNIEnv
*
env
,
static
AllocatedPath
ToAbsolutePath
(
JNIEnv
*
env
,
jobject
file
)
noexcept
;
jobject
file
)
noexcept
;
};
};
}
}
// namespace Java
#endif
#endif
src/java/Global.cxx
View file @
f58c14a7
/*
/*
* Copyright 2010-20
18
Max Kellermann <max.kellermann@gmail.com>
* Copyright 2010-20
21
Max Kellermann <max.kellermann@gmail.com>
*
*
* Redistribution and use in source and binary forms, with or without
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* modification, are permitted provided that the following conditions
...
@@ -30,10 +30,12 @@
...
@@ -30,10 +30,12 @@
#include "Global.hxx"
#include "Global.hxx"
namespace
Java
{
namespace
Java
{
JavaVM
*
jvm
;
void
Init
(
JNIEnv
*
env
)
noexcept
JavaVM
*
jvm
;
{
void
Init
(
JNIEnv
*
env
)
noexcept
{
env
->
GetJavaVM
(
&
jvm
);
env
->
GetJavaVM
(
&
jvm
);
}
}
}
}
// namespace Java
src/java/Global.hxx
View file @
f58c14a7
/*
/*
* Copyright 2010-20
18
Max Kellermann <max.kellermann@gmail.com>
* Copyright 2010-20
21
Max Kellermann <max.kellermann@gmail.com>
*
*
* Redistribution and use in source and binary forms, with or without
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* modification, are permitted provided that the following conditions
...
@@ -35,24 +35,26 @@
...
@@ -35,24 +35,26 @@
#include <jni.h>
#include <jni.h>
namespace
Java
{
namespace
Java
{
extern
JavaVM
*
jvm
;
void
Init
(
JNIEnv
*
env
)
noexcept
;
extern
JavaVM
*
jvm
;
static
inline
void
void
Init
(
JNIEnv
*
env
)
noexcept
;
DetachCurrentThread
()
noexcept
{
static
inline
void
DetachCurrentThread
()
noexcept
{
if
(
jvm
!=
nullptr
)
if
(
jvm
!=
nullptr
)
jvm
->
DetachCurrentThread
();
jvm
->
DetachCurrentThread
();
}
}
static
inline
gcc_pure
static
inline
gcc_pure
JNIEnv
*
GetEnv
()
noexcept
JNIEnv
*
GetEnv
()
noexcept
{
{
JNIEnv
*
env
;
JNIEnv
*
env
;
jvm
->
AttachCurrentThread
(
&
env
,
nullptr
);
jvm
->
AttachCurrentThread
(
&
env
,
nullptr
);
return
env
;
return
env
;
}
}
}
}
// namespace Java
#endif
#endif
src/java/Object.hxx
View file @
f58c14a7
/*
/*
* Copyright 2010-20
19
Max Kellermann <max.kellermann@gmail.com>
* Copyright 2010-20
21
Max Kellermann <max.kellermann@gmail.com>
*
*
* Redistribution and use in source and binary forms, with or without
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* modification, are permitted provided that the following conditions
...
@@ -37,13 +37,14 @@
...
@@ -37,13 +37,14 @@
#include <cassert>
#include <cassert>
namespace
Java
{
namespace
Java
{
/**
/**
* Wrapper for a local "jobject" reference.
* Wrapper for a local "jobject" reference.
*/
*/
typedef
LocalRef
<
jobject
>
LocalObject
;
typedef
LocalRef
<
jobject
>
LocalObject
;
class
GlobalObject
:
public
GlobalRef
<
jobject
>
{
class
GlobalObject
:
public
GlobalRef
<
jobject
>
{
public
:
public
:
/**
/**
* Constructs an uninitialized object. The method
* Constructs an uninitialized object. The method
* set() must be called before it is destructed.
* set() must be called before it is destructed.
...
@@ -52,15 +53,15 @@ namespace Java {
...
@@ -52,15 +53,15 @@ namespace Java {
GlobalObject
(
JNIEnv
*
env
,
jobject
obj
)
noexcept
GlobalObject
(
JNIEnv
*
env
,
jobject
obj
)
noexcept
:
GlobalRef
<
jobject
>
(
env
,
obj
)
{}
:
GlobalRef
<
jobject
>
(
env
,
obj
)
{}
};
};
/**
/**
* Utilities for java.net.Object.
* Utilities for java.net.Object.
*/
*/
class
Object
{
class
Object
{
static
jmethodID
toString_method
;
static
jmethodID
toString_method
;
public
:
public
:
static
void
Initialise
(
JNIEnv
*
env
);
static
void
Initialise
(
JNIEnv
*
env
);
static
jstring
toString
(
JNIEnv
*
env
,
jobject
o
)
{
static
jstring
toString
(
JNIEnv
*
env
,
jobject
o
)
{
...
@@ -70,7 +71,8 @@ namespace Java {
...
@@ -70,7 +71,8 @@ namespace Java {
return
(
jstring
)
env
->
CallObjectMethod
(
o
,
toString_method
);
return
(
jstring
)
env
->
CallObjectMethod
(
o
,
toString_method
);
}
}
};
};
}
}
// namespace Java
#endif
#endif
src/java/Ref.hxx
View file @
f58c14a7
/*
/*
* Copyright 2010-20
18
Max Kellermann <max.kellermann@gmail.com>
* Copyright 2010-20
21
Max Kellermann <max.kellermann@gmail.com>
*
*
* Redistribution and use in source and binary forms, with or without
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* modification, are permitted provided that the following conditions
...
@@ -38,15 +38,16 @@
...
@@ -38,15 +38,16 @@
#include <utility>
#include <utility>
namespace
Java
{
namespace
Java
{
/**
/**
* Hold a local reference on a JNI object.
* Hold a local reference on a JNI object.
*/
*/
template
<
typename
T
>
template
<
typename
T
>
class
LocalRef
{
class
LocalRef
{
JNIEnv
*
env
;
JNIEnv
*
env
;
T
value
=
nullptr
;
T
value
=
nullptr
;
public
:
public
:
LocalRef
()
noexcept
=
default
;
LocalRef
()
noexcept
=
default
;
/**
/**
...
@@ -90,16 +91,16 @@ namespace Java {
...
@@ -90,16 +91,16 @@ namespace Java {
operator
T
()
const
noexcept
{
operator
T
()
const
noexcept
{
return
value
;
return
value
;
}
}
};
};
/**
/**
* Hold a global reference on a JNI object.
* Hold a global reference on a JNI object.
*/
*/
template
<
typename
T
>
template
<
typename
T
>
class
GlobalRef
{
class
GlobalRef
{
T
value
;
T
value
;
public
:
public
:
/**
/**
* Constructs an uninitialized object. The method
* Constructs an uninitialized object. The method
* set() must be called before it is destructed.
* set() must be called before it is destructed.
...
@@ -140,20 +141,20 @@ namespace Java {
...
@@ -140,20 +141,20 @@ namespace Java {
operator
T
()
const
noexcept
{
operator
T
()
const
noexcept
{
return
value
;
return
value
;
}
}
};
};
/**
/**
* Container for a global reference to a JNI object that gets
* Container for a global reference to a JNI object that gets
* initialised and deinitialised explicitly. Since there is
* initialised and deinitialised explicitly. Since there is
* no implicit initialisation in the default constructor, this
* no implicit initialisation in the default constructor, this
* is a trivial C++ class. It should only be used for global
* is a trivial C++ class. It should only be used for global
* variables that are implicitly initialised with zeroes.
* variables that are implicitly initialised with zeroes.
*/
*/
template
<
typename
T
>
template
<
typename
T
>
class
TrivialRef
{
class
TrivialRef
{
T
value
;
T
value
;
public
:
public
:
TrivialRef
()
=
default
;
TrivialRef
()
=
default
;
TrivialRef
(
const
TrivialRef
&
other
)
=
delete
;
TrivialRef
(
const
TrivialRef
&
other
)
=
delete
;
...
@@ -201,7 +202,8 @@ namespace Java {
...
@@ -201,7 +202,8 @@ namespace Java {
operator
T
()
const
noexcept
{
operator
T
()
const
noexcept
{
return
value
;
return
value
;
}
}
};
};
}
}
// namespace Java
#endif
#endif
src/java/String.hxx
View file @
f58c14a7
/*
/*
* Copyright 2010-20
19
Max Kellermann <max.kellermann@gmail.com>
* Copyright 2010-20
21
Max Kellermann <max.kellermann@gmail.com>
*
*
* Redistribution and use in source and binary forms, with or without
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* modification, are permitted provided that the following conditions
...
@@ -38,11 +38,12 @@
...
@@ -38,11 +38,12 @@
#include <string>
#include <string>
namespace
Java
{
namespace
Java
{
/**
/**
* Wrapper for a local "jstring" reference.
* Wrapper for a local "jstring" reference.
*/
*/
class
String
:
public
LocalRef
<
jstring
>
{
class
String
:
public
LocalRef
<
jstring
>
{
public
:
public
:
String
(
JNIEnv
*
env
,
jstring
value
)
noexcept
String
(
JNIEnv
*
env
,
jstring
value
)
noexcept
:
LocalRef
<
jstring
>
(
env
,
value
)
{}
:
LocalRef
<
jstring
>
(
env
,
value
)
{}
...
@@ -76,7 +77,8 @@ namespace Java {
...
@@ -76,7 +77,8 @@ namespace Java {
std
::
string
ToString
()
const
noexcept
{
std
::
string
ToString
()
const
noexcept
{
return
ToString
(
GetEnv
(),
Get
());
return
ToString
(
GetEnv
(),
Get
());
}
}
};
};
}
}
// namespace Java
#endif
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment