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
* modification, are permitted provided that the following conditions
...
...
@@ -36,23 +36,24 @@
#include <cassert>
namespace
Java
{
/**
/**
* Wrapper for a local "jclass" reference.
*/
class
Class
:
public
LocalRef
<
jclass
>
{
public
:
class
Class
:
public
LocalRef
<
jclass
>
{
public
:
Class
(
JNIEnv
*
env
,
jclass
cls
)
noexcept
:
LocalRef
<
jclass
>
(
env
,
cls
)
{}
Class
(
JNIEnv
*
env
,
const
char
*
name
)
noexcept
:
LocalRef
<
jclass
>
(
env
,
env
->
FindClass
(
name
))
{}
};
};
/**
/**
* Wrapper for a global "jclass" reference.
*/
class
TrivialClass
:
public
TrivialRef
<
jclass
>
{
public
:
class
TrivialClass
:
public
TrivialRef
<
jclass
>
{
public
:
void
Find
(
JNIEnv
*
env
,
const
char
*
name
)
noexcept
{
assert
(
env
!=
nullptr
);
assert
(
name
!=
nullptr
);
...
...
@@ -76,7 +77,8 @@ namespace Java {
env
->
DeleteLocalRef
(
cls
);
return
true
;
}
};
}
};
}
// namespace Java
#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
* 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
* modification, are permitted provided that the following conditions
...
...
@@ -35,28 +35,30 @@
#include <jni.h>
namespace
Java
{
class
Exception
:
public
std
::
runtime_error
{
public
:
class
Exception
:
public
std
::
runtime_error
{
public
:
explicit
Exception
(
JNIEnv
*
env
,
jthrowable
e
)
noexcept
;
};
};
/**
/**
* Check if a Java exception has occurred, and if yes, convert
* 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.
*
* @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
();
if
(
result
)
env
->
ExceptionClear
();
return
result
;
}
}
}
// namespace Java
#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
* modification, are permitted provided that the following conditions
...
...
@@ -37,13 +37,14 @@
class
AllocatedPath
;
namespace
Java
{
/**
/**
* Wrapper for a java.io.File object.
*/
class
File
:
public
LocalObject
{
class
File
:
public
LocalObject
{
static
jmethodID
getAbsolutePath_method
;
public
:
public
:
gcc_nonnull_all
static
void
Initialise
(
JNIEnv
*
env
)
noexcept
;
...
...
@@ -60,7 +61,8 @@ namespace Java {
gcc_pure
gcc_nonnull_all
static
AllocatedPath
ToAbsolutePath
(
JNIEnv
*
env
,
jobject
file
)
noexcept
;
};
}
};
}
// namespace Java
#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
* modification, are permitted provided that the following conditions
...
...
@@ -30,10 +30,12 @@
#include "Global.hxx"
namespace
Java
{
JavaVM
*
jvm
;
void
Init
(
JNIEnv
*
env
)
noexcept
{
JavaVM
*
jvm
;
void
Init
(
JNIEnv
*
env
)
noexcept
{
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
* modification, are permitted provided that the following conditions
...
...
@@ -35,24 +35,26 @@
#include <jni.h>
namespace
Java
{
extern
JavaVM
*
jvm
;
void
Init
(
JNIEnv
*
env
)
noexcept
;
extern
JavaVM
*
jvm
;
static
inline
void
DetachCurrentThread
()
noexcept
{
void
Init
(
JNIEnv
*
env
)
noexcept
;
static
inline
void
DetachCurrentThread
()
noexcept
{
if
(
jvm
!=
nullptr
)
jvm
->
DetachCurrentThread
();
}
}
static
inline
gcc_pure
JNIEnv
*
GetEnv
()
noexcept
{
static
inline
gcc_pure
JNIEnv
*
GetEnv
()
noexcept
{
JNIEnv
*
env
;
jvm
->
AttachCurrentThread
(
&
env
,
nullptr
);
return
env
;
}
}
}
// namespace Java
#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
* modification, are permitted provided that the following conditions
...
...
@@ -37,13 +37,14 @@
#include <cassert>
namespace
Java
{
/**
/**
* Wrapper for a local "jobject" reference.
*/
typedef
LocalRef
<
jobject
>
LocalObject
;
typedef
LocalRef
<
jobject
>
LocalObject
;
class
GlobalObject
:
public
GlobalRef
<
jobject
>
{
public
:
class
GlobalObject
:
public
GlobalRef
<
jobject
>
{
public
:
/**
* Constructs an uninitialized object. The method
* set() must be called before it is destructed.
...
...
@@ -52,15 +53,15 @@ namespace Java {
GlobalObject
(
JNIEnv
*
env
,
jobject
obj
)
noexcept
:
GlobalRef
<
jobject
>
(
env
,
obj
)
{}
};
};
/**
/**
* Utilities for java.net.Object.
*/
class
Object
{
class
Object
{
static
jmethodID
toString_method
;
public
:
public
:
static
void
Initialise
(
JNIEnv
*
env
);
static
jstring
toString
(
JNIEnv
*
env
,
jobject
o
)
{
...
...
@@ -70,7 +71,8 @@ namespace Java {
return
(
jstring
)
env
->
CallObjectMethod
(
o
,
toString_method
);
}
};
}
};
}
// namespace Java
#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
* modification, are permitted provided that the following conditions
...
...
@@ -38,15 +38,16 @@
#include <utility>
namespace
Java
{
/**
/**
* Hold a local reference on a JNI object.
*/
template
<
typename
T
>
class
LocalRef
{
template
<
typename
T
>
class
LocalRef
{
JNIEnv
*
env
;
T
value
=
nullptr
;
public
:
public
:
LocalRef
()
noexcept
=
default
;
/**
...
...
@@ -90,16 +91,16 @@ namespace Java {
operator
T
()
const
noexcept
{
return
value
;
}
};
};
/**
/**
* Hold a global reference on a JNI object.
*/
template
<
typename
T
>
class
GlobalRef
{
template
<
typename
T
>
class
GlobalRef
{
T
value
;
public
:
public
:
/**
* Constructs an uninitialized object. The method
* set() must be called before it is destructed.
...
...
@@ -140,20 +141,20 @@ namespace Java {
operator
T
()
const
noexcept
{
return
value
;
}
};
};
/**
/**
* Container for a global reference to a JNI object that gets
* initialised and deinitialised explicitly. Since there is
* no implicit initialisation in the default constructor, this
* is a trivial C++ class. It should only be used for global
* variables that are implicitly initialised with zeroes.
*/
template
<
typename
T
>
class
TrivialRef
{
template
<
typename
T
>
class
TrivialRef
{
T
value
;
public
:
public
:
TrivialRef
()
=
default
;
TrivialRef
(
const
TrivialRef
&
other
)
=
delete
;
...
...
@@ -201,7 +202,8 @@ namespace Java {
operator
T
()
const
noexcept
{
return
value
;
}
};
}
};
}
// namespace Java
#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
* modification, are permitted provided that the following conditions
...
...
@@ -38,11 +38,12 @@
#include <string>
namespace
Java
{
/**
/**
* Wrapper for a local "jstring" reference.
*/
class
String
:
public
LocalRef
<
jstring
>
{
public
:
class
String
:
public
LocalRef
<
jstring
>
{
public
:
String
(
JNIEnv
*
env
,
jstring
value
)
noexcept
:
LocalRef
<
jstring
>
(
env
,
value
)
{}
...
...
@@ -76,7 +77,8 @@ namespace Java {
std
::
string
ToString
()
const
noexcept
{
return
ToString
(
GetEnv
(),
Get
());
}
};
}
};
}
// namespace Java
#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